Spring Boot Configuration Annotation Processor not configured
在IDEA中,编写了自定义配置属性文件,
@Getter
@Setter
@ConfigurationProperties(prefix = "yu.xss")
public class XssProperties {
/**
* 是否开启,默认为 true
*/
private boolean enable = true;
/**
* 需要排除的 URL,默认为空
*/
private List<String> excludeUrls = Collections.emptyList();
}
IDEA提示 Spring Boot Configuration Annotation Processor not configured。
如果要消除提示,解决方法如下:
1.在pom中引入
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency>
在maven-compiler-plugin插件中配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
......
<annotationProcessorPaths>
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${spring-boot.version}</version>
</path>
</annotationProcessorPaths>
......
</configuration>
</plugin>
2.在属性文件上添加注解 @ConfigurationProperties(prefix = "yu.xss")
@ConfigurationProperties(prefix = "yu.xss")
public class XssProperties {
......
}
3.在配置文件(有@Configuration的文件)上添加注解 @EnableConfigurationProperties(XssProperties.class)
@Configuration
@EnableConfigurationProperties({XssProperties.class})
public class YuWebMvcConfig implements WebMvcConfigurer {
......
}
重启IDEA,就消除提示了。
查看target/classes/META-INF/spring-configuration-metadata.json,可以看到生成了元数据。此时在application.yml编写属性时,就可以提示了,如图:
但是,这种情况只能在项目成功编译之后,才会有辅助提示。如果此时执行maven clean,再在application.yml编写属性时,就没有提示了。
可以把元数据spring-configuration-metadata.json放到src/main/resources/META-INF/下面,就会一直有辅助提示了。
如果遇到下面的提示
执行maven compile即可。
