The problem

Kotlin uses the @ConfigurationProperties annotation, and there is no prompt for editing the Application.Yaml file.

The configuration class

@ConstructorBinding
@ConfigurationProperties(prefix = "application")
data class AppConfig(
    val storage: AppConfigStorage,
)

data class AppConfigStorage(
    val namespace: String,
)

Start the class

@ConfigurationPropertiesScan
@SpringBootApplication
class EasyQuestionnaireApplication

fun main(args: Array<String>) {
    runApplication<EasyQuestionnaireApplication>(*args)
}

pom.xml

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

The test case

@SpringBootTest
internal class AppConfigTest {

    @Autowired
    private lateinit var appConfig: AppConfig

    @Test
    fun test() {
        println("""namespace:${appConfig.storage.namespace}""")
    }
}

It works fine, but the application.yaml file does not prompt.

Trying to turn on the Settings on IDEA and checking Annotation Processors -> enabling Annotation Processors didn’t work either

why

After looking at the generated files in the target directory, we found that the spring-configuration-metadata.json file was not generated properly.

The solution

I found the problem on StackOverflow.

The solution was finally found on GitHub.

Add Execution to pom.xml

<plugins> <plugin> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-plugin</artifactId> <executions> <! > < Execution > < ID >kapt</ Goals > <goal>kapt</ Goals > < Configuration > < PathPaths > <annotationProcessorPath> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <! - your own springboot version - > < version > ${springboot. Version} < / version > < / annotationProcessorPath > < / annotationProcessorPaths > </configuration> </execution> <! -> </ resultb1 <dependencies> <dependency> < grouppid > org.jetBrains. kotlin</ grouppid > <artifactId>kotlin-maven-allopen</artifactId> <version>${kotlin.version}</version> </dependency> <dependency> <groupId>org.jetbrains.kotlin</groupId> <artifactId>kotlin-maven-noarg</artifactId> <version>${kotlin.version}</version>  </dependency> </dependencies> </plugin> </plugins>

Compilation commands are executed each time the spring-configuration-metadata.json file is generated

mvn compile

The results of

After the above steps, the spring-configuration-metadata.json file is successfully generated. The IDEA can also be prompted in the application.yaml file normally.