问题描述
我正在尝试为基于Spring Boot的项目生成spring-configuration-metadata.json文件。如果我使用Java @ConfigurationProperties 类,它会自动生成并自动生成:
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;
}
}
但如果我使用Kotlin类春天未生成-configuration-metadata.json 文件(我已尝试 gradle build 和Idea 重建项目)。
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使用构造函数,getter和setter生成相同的类,并且应该充当常规Java bean。
AFAIK Kotlin generates the same class with constructor, getters and setters and should act as regular Java bean.
为什么 spring-boot-configuration-processor 不适用于Kotlin类的任何想法?
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"
...
}
到 build.gradle 文件,在命令行中运行 gradle compileJava 并打开注释IntelliJ Idea设置中的处理构建,执行,部署 - >编译器 - >注释处理器 - >启用anotation处理。其余配置仍然是
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
另请注意,没有此行
optional "org.springframework.boot:spring-boot-configuration-processor"
IntelliJ Idea会抱怨whith
IntelliJ Idea will complain whith
$ application.properties 或 application.yml
这篇关于在IntelliT Idea for Kotlin @ConfigurationProperties类中不生成spring-configuration-metadata.json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!