Spring Boot注入自定义properties文件配置
创建wzq.properties
image.png
wzq.properties注入User实体类中
image.png
@PropertySource(value = "classpath:wzq.properties",ignoreResourceNotFound = true)
classpath:wzq.properties:配置文件路
ignoreResourceNotFound :没有找到配置文件是否报错,设置true不报错
@ConfigurationProperties("wzq")
将配置文件中wzq开头的配置,安装实体类的pojo命名与配置文件对应注入值
Controller类
image.png
注入成功
image.png
个人微信公众,经常更新一些实用的干货: