我们正在 spring boot 版本 1.5.10
上运行
JDK : 1.8.0.52
我们的 gradle 文件有条目
compile group: 'org.springframework.security', name: 'spring-security-web', version: '4.2.3.RELEASE'
我们已在 application.properites 中禁用它
management.security.enabled=false
我们使用application-development.properties
来设置生产变量
当我们在生产环境中运行时,该值不受影响
我们是否需要在application-development.properties
中再次显式设置它?
最佳答案
您可以使用多个配置文件并将设置拆分到任何文件中。 对于默认启动应用程序,将获得 application.properties 中的所有设置, 用于使用“生产”配置文件运行的生产,并将添加到 application-development.properties 中的默认新设置 fot test 将使用 application-test.properties 并使用 test profile 命令运行。
向 pom.xml 添加类似此样式的内容
<profiles>
<profile>
<id>h2</id>
<properties>
<activatedProperties>h2</activatedProperties>
</properties>
</profile>
<profile>
<id>postgres</id>
<properties>
<activatedProperties>postgres</activatedProperties>
</properties>
</profile>
</profiles>
在 application.properties 中找到 spring.profiles.active=@activeProfiles@ 并使用配置文件运行
或者您可以仅使用一个设置文件 = 一个配置文件,请参见示例 https://stackoverflow.com/a/25674407/2662111
关于java - 当值不在环境文件中时 spring 属性文件的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52199964/