springboot项目自定义类在配置文件中的提示
生活随笔
收集整理的這篇文章主要介紹了
springboot项目自定义类在配置文件中的提示
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
一、寫在前面
二、加依賴
三、打包時不需要將配置處理器打進去,排除即可
四、測試
一、寫在前面
springboot自定義的bean,綁定配置文件之后通常是不會有提示的。
二、加依賴
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId><optional>true</optional> </dependency>三、打包時不需要將配置處理器打進去,排除即可
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.springframework.boot</groupId><artifactId>spring-boot-configuration-processor</artifactId></exclude></excludes></configuration></plugin></plugins> </build>四、測試
// bean 只有在容器中的組件,才會擁有SpringBoot提供的強大功能 @ToString @Data @Component // 導入配置文件的配置,映射到字段中 @ConfigurationProperties(prefix = "mycar") public class Car { private String brand; private Integer price;// application.properties mycar.brand=YD mycar.price=100000總結
以上是生活随笔為你收集整理的springboot项目自定义类在配置文件中的提示的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: spring系列-注解驱动原理及源码-声
- 下一篇: springboot使用webjars引