@ConfigurationProperties(prefix = "server-options") 抛出 SpringBoot Configuration Annotation Processor not configured 错误
说明
spring-boot-configuration-processor 包的作用是自动生成 META-INF/spring-configuration-metadata.json 文件,而这个 json 文件可以为我们在配置 application.yml 文件时提供智能提示、自动补全、注释、跳转到 java 代码(ctrl+鼠标左键)的功能。
这样一来,在开发过程中就会避免写错配置项的问题,也可以增加编码流畅感
完美集成步骤
在 pom.xml 的 dependencies 节点中加入
spring-boot-configuration-processor包的 maven 依赖<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
<version>2.5.2</version>
</dependency>
检查有没有在 pom.xml 中配置
build/plugins/[artifactId=maven-compiler-plugin]/configuration/annotationProcessorPaths
如果没有配置,可以跳到第 3 点了
如果配置了,那么一定要在annotationProcessorPaths加入spring-boot-configuration-processor包的path节点,如下:<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.5.2</version>
</path>
注意
version和dependencies节点中的一致,可以在properties节点中声明该包的版本号,然后在以上两个地方引用声明的变量编写自己的 XXProperty,如下:
package com.example.springboottests; import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.stereotype.Component; @Getter
@Setter
@Component
@ConfigurationProperties(prefix = "server-options")
public class ServerProperty {
/**
* 名称
*/
private String name; /**
* 其他配置
*/
@NestedConfigurationProperty
private ServerOtherProperty api; @Getter
@Setter
public static class ServerOtherProperty {
/**
* 标题
*/
private String title;
}
}
完毕,现在可以去
resources/application.yml查看效果了

必读的注意事项
- 每次修改
ServerProperty中的内容时,必须要 rebuild 项目,因为他是通过编译帮助我们自动生成META-INF/spring-configuration-metadata.json文件,所以如果不 rebuild,json 文件内容就不会变。 - 如果不生效,可以自己看下是不是修改了 pom.xml 但没有点击右上角的刷新按钮,或者删除
target目录再 build 试试
@ConfigurationProperties(prefix = "server-options") 抛出 SpringBoot Configuration Annotation Processor not configured 错误的更多相关文章
- idea中的springboot+gradle项目报错springboot configuration annotation processor not found in classpath
idea中的springboot项目,打开某个类run.halo.app.config.properties.HaloProperties.java,报错(使用gradle编译): springboo ...
- SpringBoot中使用@ConfigurationProperties提示:Configuration Annotation Processor not found in classpath
问题 Springboot1.5以上版本,在使用 @ConfigurationProperties注解的时候会提示Spring Boot Configuration Annotation Proces ...
- 解决spring boot1.5以上版本@ConfigurationProperties提示“Spring Boot Configuration Annotation Processor not.."
Springboot1.5以上版本,在使用 @ConfigurationProperties注解的时候会提示“Spring Boot Configuration Annotation Processo ...
- PHP 的异常处理、错误的抛出及回调函数等面向对象的错误处理方法
PHP 的异常处理.错误的抛出及回调函数等面向对象的错误处理方法: http://www.jb51.net/article/32498.htm http://www.cnblogs.com/hongf ...
- 论如何优雅的抛出SpringBoot注解的异常
平时我们在写代码的时候肯定要进行很多参数验证,最开始的时候我们一般都是这样处理的 如下图 看起来好像也没什么,但是 如果参数多了呢?你就会看到这样的校验 OMG!!! 有没有感觉稍微有点视觉 ...
- CocoaPods 抛出[!] Unable to satisfy the following requirements: 错误
今天使用CocoaPods管理ReactiveCocoa,抛出以下错误 [!] Unable to satisfy the following requirements: - `ReactiveCoc ...
- 使用@ConfigurationProperties注解 提示 “Spring Boot Configuration Annotation Processor not found in classpath ”
解决方案: 在 pom.xml 添加依赖 <dependency> <groupId>org.springframework.boot</groupId> < ...
- spring boot configuration annotation processor not found in classpath
<dependency> <groupId> org.springframework.boot </groupId> <artifactId> spri ...
- 解决Spring Boot Configuration Annotation Processor not found in classpath
问题截图: 解决方式: 在pom.xml文件中添加这些依赖 <dependency> <groupId>org.springframework.boot</groupId ...
随机推荐
- python 保存图片被截断
运行如下代码发现横坐标属性值被截断 plt.savefig('D:\\project\\python\\zhifangtu\\a.png') plt.show() plt.savefig('D:\\p ...
- Markdown语法1
Markdown是一种轻量级标记语言. Markdown 编写的文档可以导出 HTML .Word.图像.PDF.Epub 等多种格式的文档. Markdown 编写的文档后缀为 .md, .mark ...
- USB2.0接口EMC设计标准电路
- Web 开发中 Blob 与 FileAPI 使用简述
本文节选自 Awesome CheatSheet/DOM CheatSheet,主要是对 DOM 操作中常见的 Blob.File API 相关概念进行简要描述. Web 开发中 Blob 与 Fil ...
- hibernate数据源
Hibernate的描述文件可以是一个properties属性文件,也可以是一个xml文件.下面讲一下Hibernate.cfg.xml的配置.配置格式如下:1. 配置数据源 在Hibernate ...
- 启动两个jboss需要修改的端口号 (两个不能相同)
standalone-configuration-standalone.xml
- wx:key报错does not look like a valid key name
把花括号去掉就行了, 现在改版了, 要注意了 wx:key="index"
- HTML5 meta标签的用法
声明文档使用的字符编码:<meta charset="utf-8" />声明文档的兼容模式:<meta http-equiv="X-UA-Compati ...
- Python入门-面向对象-特殊方法
调用拦截功能 class Message: def send(self,info): print("消息发送:",info) class Me: def __getattribut ...
- Spring相关的API-ApplicationContext
1.ClassPathXmlApplicationContext 它是从类的根路径下加载配置文件推荐使用这种 public class UserController { public static v ...