Spring Boot 读取配置文件方法
目录
1. 使用@Value方式读取,示例如下
在 application.properties
中加入如下内容
id:: 635f50fb-51f7-4760-af1a-4e93fa368d63
|
|
然后在类中可以使用 @Value
注解取值
|
|
2. 使用Environment方式取值
同样,以读取方式一中的配置文件内容为例
|
|
3. 自定义配置文件映射
在 application.properties
文件加入内容如下。
|
|
新建实体 Test.java
,内容如下。
|
|
可以使用 @PropertySource("classpath:my2.properties")
指定读取的配置文件。