简体   繁体   中英

Documenting configuration for a Spring Boot application

I have a Spring Boot application that supports various configuration properties that can be set using application.yaml, environment variables or system properties. At the moment, the only way to figure out what properties are supported is to ask around other developers or dig into the code for property objects. Is there a way to generate some form of documentation better than this? I searched and just cannot find any answer, seems nobody is documenting their configuration or is doing it in an ad hoc manual way. Ideally, the beans configurable through properties would have Javadoc-style comments, they would be scanned by a Spring tool and that would generate an HTML or Markdown document with all the supported properties and the description extracted from Javadoc-style comments.

You could try generating a config metadata file with the spring-boot-configuration-processor as described in the Spring docs . Spring will then generate a file called spring-configuration-metadata.json where all fields of all @ConfigurationProperties classes will be included. If the field in the Proeprties class is annotated with a Javadoc comment, this comment will be included in the JSON as well. In IntelliJ, if you display the description of a config property, this comment will then be shown in the popup.

This will however only work for classes annotated with @ConfigurationProperties . That means that classes obtaining configuration properties by directly injecting them with the Spring @Value annotation (eg @Value("${myapp.my-setting}") ) this approach won't work. But as far as I know this might be the approach with which you can get the most out of Spring automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM