springboot第三天

新创建的局部配置文件与组件类绑定的注解
@PropertySource(value = {"classpath:emp.properties"})


想要加载xml的信息,在主配置类(也就是springboot启动类)上添加注解
@ImportResource(locations ={"classpath:spring01.xml "} )


yml可以通过 --- 分成块,每块都可以有各自的配置,相同的配置也可以

profile多环境支持
第一种:yml全局配置格式

spring
  profiles:
    active: xx

第二种:
在项目里的Environment的program arguments写上
spring.profiles.active=xx

第三种:jar包
运行jar包命令后加 --spring.profiles.active=xx

配置文件的默认扫描级别(从高到低)

工程的config的properties
工程的properties
resources的config的properties
resources的properties

备注:如果有多个工程,放在当前工程下的properties或config里的properties在被扫描时会扫描到第一个工程的工作目录,所以
当前工程的配置文件路径
在项目里的Environment的Working directory写上
$MODULE_DIR$

配置文件属性网址

https://docs.spring.io/spring-boot/docs/2.0.6.RELEASE/reference/htmlsingle/#common-application-properties

发布了97 篇原创文章 · 获赞 11 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/programmer188/article/details/104401469