我希望使用spring 4基于服务器环境(如stage、uat、qa等)自动加载属性文件。
但是,这并不是自动检测域系统环境变量。我们在系统中手动配置。
请大家帮忙解决这个问题。
发布于 2017-04-17 07:33:25
您可以覆盖默认的spring配置。假设您正在使用spring-boot并具有fat可执行文件jar,您可以使用命令行params使用外部覆盖内部配置文件属性,如下所示
java -jar your-executable-fat-jar.jar --spring.config.name=external-prop-file-name --spring.config.location=classpath:/application.yml,file://<external-config-file-parent-dir-path-NOT-EXTERNAL-CONFIG-FILE-PATH>哪里
spring.config.name - external config file name
spring.config.location - Locations to look for configuration files. spring.config.location可以被命名为env。因此,您将为每个包含env特定配置的env提供单独的目录。
最终命令可能如下所示:
java -jar app.jar --spring.config.name=application.yml --spring.config.location=classpath:/application.yml,file:///app/config/$CURRENT_ENV
假设您当前的env值是在CURRENT_ENV中设置的,并且所有env特定的信任目录都遵循/app/config/<env_name>规则
https://stackoverflow.com/questions/43447062
复制相似问题