I try to make completion for custom properties in Spring Boot.
I tried to create a simple project via IntelliJ IDEA 2016.3:
You have to mention in the main class the class you want to use @ConfigurationProperties annotation like below.
@EnableConfigurationProperties(AppProperties.class)
The Property Configuration class with @ConfigurationProperties will be like this
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "app")
public class AppProperties {
String name;
String id;
}
The Main class will be like this
import com.auth2.demo.config.AppProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
@SpringBootApplication
@EnableConfigurationProperties(AppProperties.class)
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
According to the Spring Boot docs, the correct configuration since Gradle 4.6 is
dependencies {
annotationProcessor group: 'org.springframework.boot', name: 'spring-boot-configuration-processor'
// ...
}
IntelliJ IDEA supports annotationProcessor
scope since build 193.3382 (2019.3). Don't forget to enable annotation processing in IntelliJ IDEA settings.
In maven project helps adding dependency spring-boot-configuration-processor and marking main class with @EnableConfigurationProperties(AppProperties.class).
Maybe somebody helps.
It happens to me for two reasons in IDEA:
I had the same problem with IntelliJ version 2018.1.2. I also had to define the actual version of spring-boot-configuration-processor in order to get it worked:
compile('org.springframework.boot:spring-boot-configuration-processor:2.0.1.RELEASE')
following works for me:
buildscript {
repositories {
jcenter()
maven { url 'https://repo.jenkins-ci.org/public/' }
maven { url 'http://repo.spring.io/plugins-release' }
}
dependencies {
classpath "io.spring.gradle:propdeps-plugin:0.0.9.RELEASE"
}
}
...
apply plugin: 'propdeps'
apply plugin: 'propdeps-eclipse'
apply plugin: 'propdeps-idea'
...
dependencyManagement {
imports {
mavenBom 'org.springframework.boot:spring-boot-starter-parent:2.0.0.RELEASE'
}
}
...
dependencies {
compile "org.springframework.boot:spring-boot-starter"
compile "org.springframework.boot:spring-boot-starter-actuator"
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor" // for @ConfigurationProperties, make sure compileJava.dependsOn(processResources)
...
}
compileJava.dependsOn(processResources)