Spring boot 中配置文件使用

#Spring boot 中配置文件使用

文件位置

Spring boot 的Application.properties 配置文件可以是以下几个地方:
classpath:/
classpath:/config/
file:./
file:./config/.

resources 目录下的用classpath
其他用file

加载顺序是

file:./custom-config/
classpath:custom-config/
file:./config/
file:./
classpath:/config/
classpath:/

常用办法

  • 可以通过spring.config.name 修改默认的配置文件名称
    比如:
    $ java -jar myproject.jar --spring.config.name=myproject

  • 可以通过spring.config.location指定配置文件
    比如:
    $ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties

  • 可以通过spring.config.location指定配置文件的位置
    比如:
    $ java -jar myproject.jar --spring.config.additional-location=classpath:/custom-config/,file:./custom-config/

@PropertySource

@PropertySource(value = {“classpath:test.properties”}, encoding = “UTF-8”)
value 中也适用启动jar 非resources还是用file

相关推荐

  1. Spring boot 配置文件使用

    2024-01-09 06:48:02       39 阅读
  2. 在Rust使用ini配置文件

    2024-01-09 06:48:02       16 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-09 06:48:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-09 06:48:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-09 06:48:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-09 06:48:02       20 阅读

热门阅读

  1. python知识图谱-py2neo实现neo4j的dao类

    2024-01-09 06:48:02       36 阅读
  2. Ajax常见请求方法(详细)

    2024-01-09 06:48:02       41 阅读
  3. Teemp - 一款免费开源 IP 管理工具

    2024-01-09 06:48:02       39 阅读
  4. Hive学习(14)json解析get_json_object()函数

    2024-01-09 06:48:02       37 阅读
  5. Android-JVM基础

    2024-01-09 06:48:02       33 阅读