目前是用 maven 的 profile 实现多数据源配置文件,但是需求要运维人员可以实现自己输入数据库的连接地址! 有类似 mvn package -自定义配置 jdbc:oracle:thin:@127.0.0.1:1521/dev 的打包方式么?
1
lululau 2019 年 5 月 23 日
配置放在 jar 的外面,让你的程序支持从指定的文件读取配置,比如 spring-boot 就是支持的
|
2
yinzhili 2019 年 5 月 23 日
类似 --spring.config.location=/path-to/config.properties 这样指定外部配置就可以了
|
4
HuHui 2019 年 5 月 23 日
直接 config server 一步到位吧
|
5
eefnrowe 2019 年 5 月 23 日
推荐 apollo
|
6
gaius 2019 年 5 月 23 日
hosts 吧,简单
|
7
bianjp PRO Maven resource filtering:
https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html |
8
xuanbg 2019 年 5 月 24 日
配置中心搞起来
|
9
guixiexiezou 2019 年 5 月 24 日
把配置文件放 jar 外面一层不就可以了。这年头真把配置文件放 jar 里面,真的是稳定啊
|
10
lwj0821 OP @guixiexiezou,已经解决了,在运维发布时读取外部配置文件,开发时读取内部配置文件。。。对于多配置文件开发运维切换也是麻烦的事。
|
11
pmispig 2019 年 5 月 24 日
@Component
@PropertySource(value = "file:d:/java/object/application.properties",ignoreResourceNotFound = true,encoding="utf-8") @PropertySource(value = "file:/app/config/application.properties",ignoreResourceNotFound = true,encoding="utf-8") 这样子就行了,开发和线上都能读外部 |
12
lwj0821 OP @pmispig 因为项目用的 hibernate,我在 xml 里配置
<!--本地配置--> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:config/config.properties</value> </list> </property> </bean> <!--线上配置--> <context:property-placeholder location="file:xxx/config/config.properties" order="1" ignore-resource-not-found="true" ignore-unresolvable="true" /> 这个首先会走线上,如果找不到配置文件会走本地的配置 |
13
lazyfighter 2019 年 5 月 30 日
模板文件,上线的时候 ci 负责渲染
|
14
lwj0821 OP 这是我后续的解决方法:直接修改 jar 包内文件
( 1 )使用 jar tvf jar 名称 | grep 目标文件名 查询出目标文件在 jar 包中的目录 :jar tvf service-0.0.1-SNAPSHOT.jar |grep config.properties ( 2 )使用 jar xvf jar 名称 目标文件名(copy 上面查出的全路径) 将目标文件及所在 jar 包中的目录解压到当前路径 :jar xvf service-0.0.1-SNAPSHOT.jar BOOT-INF/classes/config/config.properties ( 3 )修改目标文件的内容,或者将要新的目标文件替换掉提取出来的目标文件 :vim BOOT-INF/classes/config/config.properties 或 :cp config/config.properties BOOT-INF/classes/config/config.properties ( 4 )使用 jar uvf jar 名称 目标文件名(和步骤( 2 )中的目标文件名相同) 将新目标文件替换到 jar 包中 :jar uvf service-0.0.1-SNAPSHOT.jar BOOT-INF/classes/config/config.properties |