目录
一、写在前面
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