[英]Externalize Config File Java Spring
I have a legacy Spring project which has multiple configuration files located in class path.我有一个遗留的 Spring 项目,它有多个位于类路径中的配置文件。
With the pre-suggested command for compiling and packaging this project I use the following command:使用预先建议的用于编译和打包此项目的命令,我使用以下命令:
mvn package appassembler:assemble -P dev
and it make jar file as well as a script for running the project ,and every thing working fine.它制作了 jar 文件以及用于运行项目的脚本,并且一切正常。
But, the challenging is this approach put all artifacts including config files into the jar file and in deployment, I should unpackaging the jar file, changing configurations and repackage it again.(eg changing ports, IPs and some credentials ,...)但是,具有挑战性的是这种方法将包括配置文件在内的所有工件放入 jar 文件中,在部署中,我应该解压缩 jar 文件,更改配置并再次重新打包。(例如更改端口、IP 和一些凭据,...)
I want to know, is there any way telling appassembler to put config files outside the jar or any other way to solve the problem with the minor code change ?我想知道,有没有办法告诉 appassembler 将配置文件放在 jar 之外或任何其他方式来解决小代码更改的问题?
Although, it is possible using -Dspring.config.location but, every time I compile the project I have to change the script which is created by the appassembler.虽然可以使用 -Dspring.config.location 但是,每次编译项目时,我都必须更改由 appassembler 创建的脚本。
Spring Properties File Outside jar jar 外的 Spring 属性文件
spring.config.import=file:./additional.properties,optional:file:/Users/home/config/jdbc.properties
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.