Spring configuration properties metadata json for nested list of Objects

后端 未结 3 1294
醉梦人生
醉梦人生 2021-02-05 23:47

How does one configure spring configuration metadata json for nested list of objects?

Scenario

@ConfigurationProperties(prefix = \"custom-config\")
pub         


        
3条回答
  •  借酒劲吻你
    2021-02-06 00:13

    What you have already done works fine with Spring Boot, even though the IDE does not recognise these properties. What Robert Thomton suggested is the way to go if you want to improve how the IDE works with Spring Boot configuration yaml files.

    IntelliJ workaround

    These yellow markers in IntelliJ are warning markers that originate from inspection (preferences -> editor -> inspections). These markers can in many cases be ignored since they are often false positives when using new features of frameworks and languages. So if they bother you enough you could disable them for just Spring Yaml files.

    Further investigation

    For this to work you need to have spring-boot-configuration-processor as a dependency

    
        org.springframework.boot
        spring-boot-configuration-processor
        true
    
    

    IntelliJ seems to use the spring-configuration-metadata.json to identify the mappings used in Spring Boot Configuration yaml files. Which is in correspondence with Spring Boot Configuration meta-data documentation. The metadata file you listed does not contain entries for the properties of NestedObject. If you hover over the yellow lines and toggle quick fix, IntelliJ will suggest a fix:

    IntelliJ will create this file for you:

    The warnings will not immediately go away. But if you do a clean build (depending on your build tool) they will go away.

    If you now open target/META-INF/spring-configuration-metadata.json you can see that Spring Boot has added the contents of the additional-spring-configuration-metadata.json that the previous 'quick fix' generated.

    You can modify this additional-spring-configuration-metadata.json file to provide additional help for the IDE, such as valid values in the properties. Hopefully over time IntelliJ will be smart enough so we won't need to manually edit this file.

    That did it for the original warnings, but now If you look into application.yaml you can see some new warnings:

提交回复
热议问题