一般使用spring.config.location引用为任意位置配置文件
1.我的项目目录结构


2.第一种在配置文件中spring.config.location引用了另一个配置文件
注:
因为spring.config.location优先级低,执行application.yml时此属性已经有默认值,所以放到内部不会生效
3.第二种命令行启动时指定spring.config.location引用的配置文件
注:
这种方式不会引用jar包内的配置文件,只会引用 --spring.config.location指定的配置文件
java -jar zzxt-gather.jar --spring.config.location=d:\aaa\zzxt-gather\application.yml,d:\aaa\application.yml java -jar zzxt-gather.jar --spring.config.location=.\application.yml,..\application.yml
4.两个配置文件
d:\aaa\zzxt-gather\application.yml
server:
address:
port: 9010
servlet:
context-path: /zzxt-gather
session:
timeout: 1800
#aa: aa
#==== 项目自用配置
service.url: http://localhost:9020/zzxt-service
#voc文件路径
vocs.dirpath: d:\\test\\
#voc文件另存路径
vocs.cpdirpath: d:\\test2\\
#port:voc server监听的端口
vocs.server.port: 9021
#charset:生产环境应为“utf-8”
vocs.server.charset: gbk
aa: aa
spring.config.location: d:\aaa\application.ymld:\aaa\application.yml
spring:
#mysql数据库
datasource:
main:
jdbc-url: jdbc:mysql://192.168.2.101:3306/zzxt_main?useunicode=true&characterencoding=utf-8&allowmultiqueries=true&servertimezone=gmt%2b8
username: gmp
password: bw.2018总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论