首页 > 其他分享 >Spring Boot Configuration Annotation Processor not configured

Spring Boot Configuration Annotation Processor not configured

时间:2023-04-25 11:45:33浏览次数:39  
标签:JwtProperties String Spring configured boot JWT Boot spring configuration

一、Spring boot自定义配置实现自动提示

@ConfigurationProperties 的作用: 让JavaBean中属性值要和配置文件进行映射

@Getter
@Setter
@ConfigurationProperties(prefix = "jwt")
public class JwtProperties {
    /**
     * JWT加解密使用的密钥
     */
    private String secret;
    /**
     * JWT的过期限时间
     */
    private String expiration;
    /**
     * JWT负载中拿到开头
     */
    private String tokenHead;
    /**
     * JWT存储的请求头
     */
    private String tokenHeader;
 
}

二、在启动类中加入@EnableConfigurationProperties 注解

@EnableConfigurationProperties 注解的作用:让使用了 @ConfigurationProperties 注解的类生效。

@EnableConfigurationProperties({JwtProperties.class})
@SpringBootApplication
public class SeadogAdminApplication {
	public static void main(String[] args) {
		SpringApplication.run(SeadogAdminApplication.class, args);
	}
}

三、idea中会提示SpringBoot Configuration Annotation Processor not configured的错误

img

四、解决方法

您在使用@ConfigurationProperties注解时可以使用spring-boot-configuration-processor jar 轻松地从带有注释的项目中生成自己的配置元数据文件。该jar包含一个Java注释处理器,在您的项目被编译时会被调用。要使用处理器,请包含对的依赖spring-boot-configuration-processor。

1.添加spring-boot-configuration-processor的依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <optional>true</optional>
</dependency>

重新buil了项目,你会发现问题还没有解决,idea还是提示:SpringBoot Configuration Annotation Processor not configured的错误。

2.在maven-compiler-plugin内的annotationProcessorPaths中添加相应path

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>UTF-8</encoding>
                <annotationProcessorPaths>
                    <path>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-configuration-processor</artifactId>
                        <version>${springboot.version}</version>
                    </path>
                </annotationProcessorPaths>
            </configuration>
        </plugin>
    </plugins>
</pluginManagement>

3.maven-clean 重新build一下项目,会在target->classes->META-INF目录下生成配置元数据文件:spring-configuration-metadata.json

img

打开spring-configuration-metadata.json文件

{
  "groups": [
    {
      "name": "jwt",
      "type": "com.seadog.common.security.config.JwtProperties",
      "sourceType": "com.seadog.common.security.config.JwtProperties"
    }
  ],
  "properties": [
    {
      "name": "jwt.expiration",
      "type": "java.lang.String",
      "description": "JWT的过期限时间",
      "sourceType": "com.seadog.common.security.config.JwtProperties"
    },
    {
      "name": "jwt.secret",
      "type": "java.lang.String",
      "description": "JWT加解密使用的密钥",
      "sourceType": "com.seadog.common.security.config.JwtProperties"
    },
    {
      "name": "jwt.token-head",
      "type": "java.lang.String",
      "description": "JWT负载中拿到开头",
      "sourceType": "com.seadog.common.security.config.JwtProperties"
    },
    {
      "name": "jwt.token-header",
      "type": "java.lang.String",
      "description": "JWT存储的请求头",
      "sourceType": "com.seadog.common.security.config.JwtProperties"
    }
  ],
  "hints": []
}

4.在application.yml中测试

img

标签:JwtProperties,String,Spring,configured,boot,JWT,Boot,spring,configuration
From: https://www.cnblogs.com/javaxubo/p/17352155.html

相关文章

  • spring boot 切片测试
    我想问大家一下使用springboot项目的时候做单元测试的时,使用的哪种方式?有很多小伙伴使用spring-boot-starter-test,但是这种测试是比较笨重的。当你想要测一个方法时,相关于把整个springboot项目启动启动测试这一个方法如果项目使用的组件很多,比如有redis,数据库,kafka,minio等......
  • SpringBoot监控Actuator,关闭redis监测
    当我们导入了spring-boot-starter-actuator这个依赖后,SpringBoot会默认去监测一些信息。其中就包括redis、会根据redis的默认初始配置,localhost:6379尝试连接redis。如果我们没有用到redis,启动就会报错<dependency><groupId>org.springframework.boot</groupId>......
  • Xxl-job安装部署以及SpringBoot集成Xxl-job使用
    1、安装Xxl-job:可以使用docker拉取镜像部署和源码编译两种方式,这里选择源码编译安装。代码拉取地址:https://github.com/xuxueli/xxl-job/tree/2.1.2官方开发文档:https://www.xuxueli.com/xxl-job/#%E3%80%8A%E5%88%86%E5%B8%83%E5%BC%8F%E4%BB%BB%E5%8A%A1%E8%B0%83%E5%BA......
  • java面试题--Spring
    一、Spring、SpringMVC、SpringBoot的区别是什么?二、????三、SpringMVC工作流程是什么?1、DispatcherServlet接收请求,将请求发给HandlerMapping;2、HandlerMapping根据请求url,匹配到要处理的handler,并包装成处理器执行链,返回给DispatcherServlet。3、DispatcherServlet根据处理器......
  • SpringBoot接口支持配置https步骤
    本地利用JDK工具生成证书1.keytool-genkey-keyalgRSA-keystoretomcat.jks2.keytool-importkeystore-srckeystoretomcat.jks-destkeystoretomcat.pkcs12-deststoretypepkcs12 验证是否成功keytool-list-vkeystoretomcat.jks keytool-list-vkeystoretom......
  • 记录一次springBoot+hibernate+JPA+swagger2+链接人大金仓的项目demo
    <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.spring......
  • P.4-前后端分类登录校验、P.6-SpringSecurity完整流程
    P.4-前后端分类登录校验P.6-SpringSecurity完整流程SpringSecurity的原理其实就是一个过滤器链,内部包含了提供各种功能的过滤器。(了解即可)UsernamePasswordAuthenticationFilter:负责处理我们在登陆页面填写了用户名密码后的登陆请求。入门案例的认证工作主要......
  • P.1-SpringSecurity简介、P.2-入门案例准备、P.3入门案例引入SpringSecurity
    P1.SpringSecurity简介SpringSecurity是Spring家族中的一个安全管理框架。一般Web应用的需要进行认证和授权认证:验证当前访问系统的是否是本系统的用户,并且要确认具体是那个用户授权:经过认证后判断当前用户是否有权限进行某个操作......
  • SpringBoot 编译运行时出现 错误: 无 效的目标发行版:1.11 的解决方法
    网上的方法大多是jdk版本不一致问题这里需要修改下所用maven的settings.xml以下贴的图是修改后,原本我这里jdk的版本号全部是1.11 修改以后就可以顺利运行了,乌鱼子......
  • No bean named 'org.springframework.context.annotation.ConfigurationClassPostProc
       今天在重启springboot时候一直报如上的代码,但是也没有具体的报错信息。很是郁闷。   最后发现有两个:一个是使用@ComponentScan的问题,一个是@MapperScan的问题。@MapperScan默认是当前目录,我的目录和我引用的dao的目录不同导致的。   2.@Autowire和@Resource......