spring boot maven子模块不起作用
豌里个豆 人气:0环境
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"; }
加载全部内容