简体   繁体   English

外部化配置文件 Java Spring

[英]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

Externalized Configuration 外化配置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring启动在Java注释上外部化配置属性/消息 - Spring boot externalize config properties/messages on Java annotations Spring Boot-外部化配置属性 - Spring boot - Externalize config properties Spring Boot 外部化应用程序配置 - Spring boot externalize application config Spring Web应用程序:如何外部化属性文件? - Web app with Spring: how externalize properties file? 如何在 spring 启动时外部化一些配置变量? - How can I externalize some config variables in spring boot? 在 Helidon MP 中外部化 microprofile-config.properties 文件的任何方式 - Any way to Externalize microprofile-config.properties file in Helidon MP 如何在java spring集成项目中外部化oauthsdk.json - How to externalize oauthsdk.json in java spring integration project 在春天在属性文件中外部化休眠查询或SQL查询 - externalize hibernate queries or sql queries in properties file in spring Spring Data JPA:将@EnableJpaRepositories basePackages配置外部化为属性文件 - Spring Data JPA : externalize to a property file the @EnableJpaRepositories basePackages configuration Java Spring参数化.xml配置文件 - Java spring parametric .xml config file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM