I'm trying to generate spring-configuration-metadata.json file for my Spring Boot based project. If I use Java @ConfigurationProperties class it is generated correctly and automatically:
@ConfigurationProperties("myprops")
public class MyProps {
private String hello;
public String getHello() {
return hello;
}
public void setHello(String hello) {
this.hello = hello;
}
}
But if I use Kotlin class the spring-configuration-metadata.json file is not generated (I've tried both gradle build and Idea Rebuild Project).
@ConfigurationProperties("myprops")
class MyProps {
var hello: String? = null
}
AFAIK Kotlin generates the same class with constructor, getters and setters and should act as regular Java bean.
Any ideas why spring-boot-configuration-processor doesn't work with Kotlin classes?
解决方案
Thank you for pointing me in the right direction. So the solution is to add
dependencies {
...
kapt "org.springframework.boot:spring-boot-configuration-processor"
optional "org.springframework.boot:spring-boot-configuration-processor"
...
}
to build.gradle file, run gradle compileJava in command line and turn on annotation processing in IntelliJ Idea settings Build, Execution, Deployment -> Compiler -> Annotation processor -> Enable anotation processing. The rest of configuration remains the same
Also note that without this line
optional "org.springframework.boot:spring-boot-configuration-processor"
IntelliJ Idea will complain whith
Cannot resolve configuration property
message in your application.properties or application.yml