Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the configuration processor with records

I am using spring-boot-configuration-processor to generate a spring-configuration-metadata.json file.

When I use a class for my configuration, the description is taken from the javadoc above the field like in this example using Lombok:

@Getter
@ConfigurationProperties("my.second.properties")
public class MySecondProperties {

    /**
     * This is the description for stringProperty
     */
    private final String stringProperty;

    /**
     * This is the description for booleanProperty
     */
    private final boolean booleanProperty;

    public MySecondProperties(@DefaultValue("default value for stringProperty") String stringProperty,
                              boolean booleanProperty) {
        this.stringProperty = stringProperty;
        this.booleanProperty = booleanProperty;
    }
}

However, when using records I do not manage to get the description. I have created a record as in the example below, but the description remains empty in the generated json-file.

/**
 * @param stringProperty This is the description for stringProperty
 * @param booleanProperty This is the description for booleanProperty
 */
@ConfigurationProperties("my.fourth.properties")
public record MyFourthProperties (@DefaultValue("default value for stringProperty") String stringProperty,
                                  boolean booleanProperty) {
}

How can I ensure that the description is filled when using records?

like image 448
mydeveloperplanet Avatar asked Oct 25 '25 05:10

mydeveloperplanet


1 Answers

As of Spring Boot 3.2.0, this doesn't seem to be possible. If you want spring-boot-configuration-processor to generate property-level documentation, you need to use a non-record Java class, possibly with Lombok annotations.

spring-projects/spring-boot#29403 more specifically notes:

... there is no way to automatically generate descriptions in configuration metadata if you use @ConfigurationProperties with record class.

That GitHub pull request attempts to add support, but as of this writing it is incomplete and not part of the Spring library stack.

like image 89
David Maze Avatar answered Oct 26 '25 23:10

David Maze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!