SpringBoot引用外部配置文件spring.config.location

一般使用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:aaazzxt-gatherapplication.yml,D:aaaapplication.yml
java -jar zzxt-gather.jar --spring.config.location=.application.yml,..application.yml

2.两个配置文件 ‪D:aaazzxt-gatherapplication.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:aaaapplication.yml

‪D:aaaapplication.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
经验分享 程序员 微信小程序 职场和发展