解决springboot configuration processor对maven子模块不起作用的问题

2022-10-18,,

这篇文章主要介绍了解决springboot 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";
}

到此这篇关于解决springboot configuration processor对maven子模块不起作用的问题的文章就介绍到这了,更多相关spring boot maven子模块不起作用内容请搜索北冥有鱼以前的文章或继续浏览下面的相关文章希望大家以后多多支持北冥有鱼!

您可能感兴趣的文章:

  • Maven 多模块父子工程的实现(含Spring Boot示例)
  • springboot+idea+maven 多模块项目搭建的详细过程(连接数据库进行测试)
  • SpringBoot+Maven 多模块项目的构建、运行、打包实战
  • SpringBoot创建maven多模块项目实战代码
  • 详解Maven 搭建spring boot多模块项目(附源码)

《解决springboot configuration processor对maven子模块不起作用的问题.doc》

下载本文的Word格式文档,以方便收藏与打印。