Override default Spring-Boot application.properties with application.properties

问题: Want to completely replace my application.properties with application-test.properties for my junit. TestPropertySource is not doing the job. Seems like it only replaces som...

问题:

Want to completely replace my application.properties with application-test.properties for my junit. TestPropertySource is not doing the job. Seems like it only replaces some of the common properties but i dont want that.

Want to load application-test.properties not application.properties in my Junit integraction test.

@RunWith(SpringRunner.class)
@ActiveProfiles( "test" )
@SpringBootTest(classes = Application.class)
@TestPropertySource(locations="classpath:application-test.properties")
@AutoConfigureMockMvc

回答1:

There is a property to that annotation that would suppress inheritance of properties:

@TestPropertySource(locations="classpath:application-test.properties", inheritProperties=false)

The default is true so you need to set that explicitly.

As per documentation:

If inheritProperties is set to false, the inlined properties for the test class will shadow and effectively replace any inlined properties defined by a superclass.


回答2:

I normally have a resources folder in my test folder (src/test/resources) where i place a modified application.properties and spring-boot should take this. See on https://www.baeldung.com/properties-with-spring 5.3

  • 发表于 2019-02-13 22:38
  • 阅读 ( 213 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除