3

I am trying to add custom variables in application.properties file. When I add, the IDEs (both Eclipse 2019-06 (4.12.0) and Spring Tool Suite 4.3.1) show the yellow warning "abc.def is an unknown property".

The problem is similar to Spring boot - custom variables in Application.properties. I tried the method given by @StephaneNicoll in the answer. It is still showing the same warning. In fact, I opened the project https://github.com/snicoll-demos/spring-boot-configuration-binding in Eclipse. It still gives the same warning. Is there anything else that I need to do?

It's a minor annoyance. But would like to get rid of it.

1 Answers1

3

You have to add spring-boot-configuration-processor to your project:

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

Then create your properties class with annotation @ConfigurationProperties and their prefix, for example:

@Data
@ConfigurationProperties(prefix = "abc")
@Validated
public class AbcProperties {

    /**
     * Description of the property 'def'.
     */
    @NotNull private Long def = 0L;  // <- default value of the property

    // other props...
}

Then enable it:

@SpringBootApplication
@EnableConfigurationProperties(AbcProperties.class)
public class AbcApplication {
    //...
}

Then rebuild your project. After these steps, the IDE will see your props correctly.

More info:

Cepr0
  • 28,144
  • 8
  • 75
  • 101