springboot常用starter⑲-spring-boot
2021-07-25 本文已影响0人
一个好汉
spring-boot-configuration-processor
引入jar之后,在application.yml中给自定义对象属性初始化值的时候会有属性名的提示
自定义配置生成元数据
引入 spring-boot-configuration-processor jar包
可以帮助我们生成元数据 进而可以在yaml配置文件跟对应的类之间进行跳转
pom.xml 增加配置
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</dependency>
spring-boot-configuration-processor
没有配置之前 idea 会出现 spring boot configuration annotation processor not configured
但是程序没有报错依旧可以正常使用
配置了 spring-boot-configuration-processor 之后错误消失
re-run spring boot configuration annotation processor to update generated metadata 重新运行Spring Boot配置注释处理器以更新生成的元数据
Re-run是指配置注解需要重新运行启动类才能生效
spring-boot-configuration-processor 这个组件是为了帮助我们自己配置生成元数据
可参考spring-boot-configuration-processor的真实作用
使用@PropertySource使用自己定义的文件
例如
@PropertySource(value = "classpath:static/config/thirdPartyInterfaceProp.properties",
encoding = "UTF-8")
在resource目录新建的配置文件 thirdPartyInterfaceProp.properties
third.party.baidu.url=https://www.baidu.com
third.party.baidu.token=personal
third.party.baidu.baseUrl=xinfei
![](https://img.haomeiwen.com/i15338236/6c7f340ca8a71d83.jpg)