【问题标题】:spring boot adding another properties file to the environmentspring boot 向环境中添加另一个属性文件
【发布时间】:2015-01-12 04:43:24
【问题描述】:

我想知道除了 application.properties 文件之外,是否可以向环境路径添加另一个属性文件。如果是这样,您如何指定新路径?因此,您可以使用 Autowired Environment 变量访问属性。目前在我的 java 项目中,默认属性文件 application.properties 的路径是 /soctrav/src.main.resources/application.properties

【问题讨论】:

    标签: java spring properties


    【解决方案1】:

    如果您想在没有命令行参数的情况下执行此操作,则可以解决问题。

    @SpringBootApplication
    @PropertySources({
            @PropertySource("classpath:application.properties"),
            @PropertySource("classpath:anotherbunchof.properties")
    })
    public class YourApplication{
    
    }
    

    【讨论】:

      【解决方案2】:

      您可以使用命令行参数指定其他属性文件:

      java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
      

      看看Application properties file Spring Boot doc chapter

      【讨论】:

        猜你喜欢
        • 2015-05-14
        • 2016-01-20
        • 1970-01-01
        • 2019-02-24
        • 2015-10-01
        • 2018-02-20
        • 2020-09-15
        相关资源
        最近更新 更多