java - 当值不在环境文件中时 spring 属性文件的行为

标签 java spring-boot java-security java-security-manager

我们正在 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/

相关文章:

java - 使用打印到屏幕上的体积的成本差异

mysql - @OnDelete Hibernate 注释不会为 MySql 生成 ON DELETE CASCADE

java - 将 .cer 证书转换为 .jks

java - EJB:自定义身份验证和授权

java - "R cannot be resolved to a variable"刚创建完android项目?

java - 为什么我的 CSS 在 Java 中不能正常工作?

java - 没有找到接口(interface) org.springframework.data.jpa.domain.Specification] 的主要或默认构造函数,其根本原因

java - 生成 SecureRandom() 的高性能方法

java - Google Guava 缓存默认过期

spring-mvc - Spring-Boot + Spring-MVC + Thymeleaf + Apache Tiles