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:\aaa\zzxt-gather\application.yml,D:\aaa\application.yml
java -jar zzxt-gather.jar --spring.config.location=.\application.yml,..\application.yml

2.两个配置文件
‪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.yml

‪D:\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
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值