• 解决spring-boot-configuration-processor对maven子模块不起作用


    环境
    idea 2021.1
    maven 3.6.1
    springboot 2.3.10.RELEASED

    问题: spring boot configuration annotation processor not configured

    单模块maven项目

    pom内添加以下依赖即可消除警告

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

    多模块且喊子模块maven项目

    在父module的pom内添加以下依赖

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-configuration-processor</artifactId>
                <!-- <optional>true</optional> 不注释掉子模块无法引用到此依赖 -->
            </dependency>
    

    然后在maven-compiler-plugin内的annotationProcessorPaths中添加相应path

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

    这样就能消除警告啦,至于自定义yml或properties的内容快捷提示且能跳转相应配置类,可以看如下简单demo

    demo

    application.yml

    my:
      a:
        name: lisi
        age: 11
        person:
          age: 12
          name: zhangsan
    

    MyConfig.java

    import lombok.Data;
    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.stereotype.Component;
    
    /**
     * <p>
     *     demo
     * </p>
     *
     * @author wandoupeas
     * @date 2021-09-16 11:48 上午
     */
    @Data
    @Component
    @ConfigurationProperties(prefix = "my.a")
    public class MyConfig {
        private String name;
        private String age;
        private MyConfigName person;
    }
    

    MyConfigName.java

    import lombok.Data;
    import org.springframework.boot.context.properties.ConfigurationProperties;
    import org.springframework.stereotype.Component;
    
    /**
     * <p>
     *     demo
     * </p>
     *
     * @author wandoupeas
     * @date 2021-09-16 11:48 上午
     */
    @Data
    @Component
    @ConfigurationProperties(prefix = "my.a.person")
    public class MyConfigName {
        private String name = "zhangsan";
    
        private String age = "123";
    }
    
  • 相关阅读:
    区别是否是 微信浏览器 ?
    添加收藏
    函数调用那点事
    移动端返回上一页,刚需!document.referrer 详解
    蓝桥杯-乘积尾零
    printf不能直接输出string类型
    bitset的简单用法
    to_string()函数(C++)
    蓝桥杯-明码
    手写C语言字符库
  • 原文地址:https://www.cnblogs.com/wandoupeas/p/spring-boot-configuration-processor-not-configured.html
Copyright © 2020-2023  润新知