[英]Override default Spring-Boot application.properties with application.properties
Want to completely replace my application.properties with application-test.properties
for my junit. 想要用我的junit的
application-test.properties
完全替换我的application.properties。 TestPropertySource
is not doing the job. TestPropertySource
没有完成这项工作。 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. 要在我的Junit \\
application.properties
测试中加载application-test.properties
而不是application.properties
。
@RunWith(SpringRunner.class)
@ActiveProfiles( "test" )
@SpringBootTest(classes = Application.class)
@TestPropertySource(locations="classpath:application-test.properties")
@AutoConfigureMockMvc
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. 默认值为
true
因此您需要显式设置。
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.
如果InheritProperties设置为false,则测试类的内联属性将隐藏并有效替换超类定义的所有内联属性。
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. 我通常在我的测试文件夹(src / test / resources)中有一个resources文件夹,我在其中放置了一个修改过的application.properties,而spring-boot应该使用这个文件夹。 See on https://www.baeldung.com/properties-with-spring 5.3
参见https://www.baeldung.com/properties-with-spring 5.3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.