当前位置: 代码网 > it编程>编程语言>Java > Spring Boot外部配置文件:spring.config.location使用技巧

Spring Boot外部配置文件:spring.config.location使用技巧

2026年08月06日 Java 我要评论
一般使用spring.config.location引用为任意位置配置文件1.我的项目目录结构2.第一种在配置文件中spring.config.location引用了另一个配置文件注:因为spring

一般使用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.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)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2026  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com