简体   繁体   English

用application.properties覆盖默认的Spring-Boot application.properties

[英]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.

相关问题 覆盖application.properties以在Spring-boot应用程序中进行集成测试 - Override application.properties for integration tests in spring-boot app 如何在 Spring-Boot 的生产过程中覆盖 application.properties? - How to override application.properties during production in Spring-Boot? 在 Junit 测试中覆盖默认的 Spring-Boot application.properties 设置 - Override default Spring-Boot application.properties settings in Junit Test 使用动态值覆盖 Junit 测试中的默认 Spring-Boot application.properties 设置 - Override default Spring-Boot application.properties settings in Junit Test with dynamic value spring-boot如何添加多个application.properties文件? - How to add multiple application.properties files in spring-boot? spring-boot application.properties中的环境变量错误 - Environment Variables in spring-boot application.properties error 春季启动application.properties问题-bug - spring-boot application.properties question -bug Spring-Boot>使用JNDI设置application.properties - Spring-Boot > Setting application.properties using JNDI application.properties 中电子邮件数据中 Spring-Boot 中的环境变量 - environment variables in Spring-Boot in email data in application.properties Spring-Boot中的application.properties属性的UTF-8编码 - UTF-8 encoding of application.properties attributes in Spring-Boot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM