Springboot(二):springboot的自定义配置

(二):springboot的自定义配置
在SpringBoot框架中,默认的是两个全局配置文件:"application.properties,application.yml",同时SpringBoot也支持识别自定义配置属性文件。
也可以自定义配置文件.
举个栗子:
1:我们写个配置文件:custom.properties


image.png

在里面写上person的属性
person1.name="huyuelin"
person1.age="30"
person1.address="长沙市"
2:写一个实体类,
并在实体类上如下三个注解
@PropertySource(value={"classpath:custom.properties"})
@Component
@ConfigurationProperties(prefix = "preson1")

image.png

prefix等于的preson1与配置文件custom.properties中的person1对应
3:写个测试方法
image.png

4:结果:
image.png

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容