Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure for Spring Boot Configuration Annotation Processor using @ConfigurationProperties on IntelliJ?

Warning

On IntelliJ, I am getting a Spring Boot Configuration Annotation Processor not configured for having @ConfigurationProperties. Below is my class:

@Configuration
@ConfigurationProperties(prefix = "abc")
@Data
@RefreshScope
class Config {
    String propA;
    String propB;
    ...
}

I am not sure what's causing this and when I click on the wrench for settings, I do not see any options to configure for metadata files.

like image 523
夢のの夢 Avatar asked Apr 22 '20 15:04

夢のの夢


2 Answers

I resolved it by adding the following dependency to my pom file

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-configuration-processor</artifactId>
    <version>2.2.6.RELEASE</version>
    <optional>true</optional>
</dependency>
like image 143
wero026 Avatar answered Sep 26 '22 01:09

wero026


I faced the same problem with IntelliJ IDEA 2020.2 and Maven 3.6.2. The solution was to explicitly set the annotation processor in the maven-compiler-plugin settings. I found the answer here:

  1. https://stackoverflow.com/a/48028193/9989732
  2. https://stackoverflow.com/a/64031211/9989732

The full configuration:

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

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.0</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>2.4.2</version>
      </path>
      <path>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.18.8</version>
      </path>
    </annotationProcessorPaths>
  </configuration>
</plugin>
like image 21
Ivan Avatar answered Sep 23 '22 01:09

Ivan