目录
问题抛出:
@ConfigurationProperties
问题抛出:
进行Spring Boot配置文件部署时,发出警告Spring Boot Configuration Annotation Processor not configured,但是不影响运行。
不过有时候springboot项目出错了并且排除了所有你认为会导致的问题的原因还是没有解决,突然看到这个错误,不免心里痒痒的。
这里我放置一下 官方解答:
To use the processor, include a dependency on spring-boot-configuration-processor
.
With Maven the dependency should be declared as optional, as shown in the following example:
(加入依赖)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
If you have defined @ConfigurationProperties
in your application, make sure to configure the spring-boot-maven-plugin
to prevent the repackage
goal from adding the dependency into the fat jar:
(如果你已经在应用中定义了 @ConfigurationProperties,请确保配置了spring-boot-maven-plugin,以防止重新打包目标将依赖项添加到fat jar中:
)
<project>
<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>
</project>
ok,那么什么是 @ConfigurationProperties ,有啥用?
@ConfigurationProperties
可以程之为 注解执行器 配置完成后,当执行类中已经定义了对象和该对象的字段后,在配置文件中对该类赋值时,便会非常方便的弹出提示信息。
例如 需要在yml,propertier...中配置 阿里云 的某些参数
@Data
@AllArgsConstructor
@ToString
@NoArgsConstructor
@Component
@ConfigurationProperties(prefix = "alipay")
public class AlipayConfig {
//应用的id app_id
@Value("${alipay.app_id}")
public String app_id;
//商户的私钥 merchant_private_key
@Value("${alipay.merchant_private_key}")
public String merchant_private_key;
//支付宝的公钥
@Value("${alipay.alipay_public_key}")
public String alipay_public_key;
//异步通知的地址
@Value("${alipay.notify_url}")
public String notify_url;
//同步跳转的页面
@Value("${alipay.return_url}")
public String return_url;
//签名方式
@Value("${alipay.sign_type}")
public String sign_type;
//字符的编码
@Value("${alipay.charset}")
public String charset;
//网关地址
@Value("${alipay.gatewayUrl}")
public String gatewayUrl;
//定义一个方法返回AlipayConfig对象
@Bean
public AlipayConfig getAlipayConfig(){
AlipayConfig alipayConfig = new AlipayConfig();
alipayConfig.setApp_id(app_id);
alipayConfig.setApp_id(merchant_private_key);
alipayConfig.setApp_id(alipay_public_key);
alipayConfig.setApp_id(notify_url);
alipayConfig.setApp_id(return_url);
alipayConfig.setApp_id(sign_type);
alipayConfig.setApp_id(charset);
alipayConfig.setApp_id(gatewayUrl);
return alipayConfig;
}
}