The documentation example looks like this:

@ConfigurationProperties(prefix = "my.properties")
public class MyProperties {

    private String name;

    @NestedConfigurationProperty
    private Nested nested = new Nested();

    // getters / setters...

    public static class Nested {

        private int number;

        // getters / setters...

    }

}

In this case, @NestedConfigurationProperty isn't required as Nested is already nested within MyProperties. It would be required if the code were structure like this:

@ConfigurationProperties(prefix = "my.properties")
public class MyProperties {

    private String name;

    @NestedConfigurationProperty
    private Nested nested = new Nested();

    // getters / setters...

}

public class Nested {

    private int number;

    // getters / setters...

}

Comment From: wilkinsona

Thanks, @mhalbritter. Sorry, I wasn't very clear above and those changes aren't what I had in mind. Rather than removing @NestedConfigurationProperty I think we need to update the example so that it is required. We can then build on that in #33235 to add some further examples with records and Kotlin data classes.

Comment From: mhalbritter

Ah, I see. I'll add an example showing when @NestedConfigurationProperties is needed.

Comment From: siddhsql

Using Spring Boot 3.1.5 I have 3 classes like this:

import jakarta.validation.constraints.*;
import lombok.Data;

@Data
public class Foo {
  @NotNull String username;
  @NotNull String password;
}
import jakarta.validation.constraints.*;
import lombok.Data;

@Data
public class Bar {
  @NotNull String firstName;
  @NotNull String lastName;
}
@Data
@ConfigurationProperties
@Component
public class Config {
  @NotNull Foo foo;
  @NestedConfigurationProperty @NotNull Bar bar; // note it is missing the initializer
}

the expectation was that parsing of application.properties should fail but in fact it works. any idea why? also the documentation is not very helpful:

This annotation has no bearing on the actual binding processes, but it is used by the spring-boot-configuration-processor as a hint that a field is not bound as a single value. When this is specified, a nested group is created for the field and its type is harvested.

Comment From: scottfrederick

@siddhsql As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements. This feels like a question that would be better suited to Stack Overflow.

If you think the documentation for @NestedConfigurationProperty needs improvement, please open a new issue with concrete examples of what you think should be added or clarified.

Comment From: siddhsql

this looks like a bug to me:

the expectation was that parsing of application.properties should fail (according to the example provided right at the beginning of this issue and latest documentation) but in fact it works.

in fact it gets doubly confusing because on one hand the documentation says to use @NestedConfigurationProperty and elsewhere the documentation says: This annotation has no bearing on the actual binding processes

PS: i do not use SO as my questions are not well received there. i was just providing feedback for improvement.

On Fri, May 24, 2024 at 1:57 PM Scott Frederick @.***> wrote:

@siddhsql https://github.com/siddhsql As mentioned in the guidelines for contributing https://github.com/spring-projects/spring-boot/blob/master/CONTRIBUTING.adoc#using-github-issues, we prefer to use GitHub issues only for bugs and enhancements. This feels like a question that would be better suited to Stack Overflow http://stackoverflow.com/.

If you think the documentation for @NestedConfigurationProperty needs improvement, please open a new issue with concrete examples of what you think should be added or clarified.

— Reply to this email directly, view it on GitHub https://github.com/spring-projects/spring-boot/issues/33239#issuecomment-2130344596, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6NWEK4SZMMDITTP6GBMRWLZD6STRAVCNFSM6AAAAAASDLOZKSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZQGM2DINJZGY . You are receiving this because you were mentioned.Message ID: @.***>

Comment From: philwebb

@siddhsql If you think you've found a bug then please open a new issue with a sample project that reproduces the issue (ideally without using lombok). I'm not sure why you think the parsing of application.properties should fail, we'll need more details if you do open an issue.

in fact it gets doubly confusing because on one hand the documentation says to use @NestedConfigurationProperty and elsewhere the documentation says: This annotation has no bearing on the actual binding processes

You should use the annotation to ensure that the correct meta-data is generated so that IDE auto-completion works. The annotation isn't actually needed for Spring Boot to perform the binding at runtime.

Comment From: siddhsql

what does IDE auto-completion have to do with this? could you explain? i mean auto-completion of what? IDE can auto-complete variables without annotations.

On Fri, May 24, 2024 at 5:51 PM Phil Webb @.***> wrote:

@siddhsql https://github.com/siddhsql If you think you've found a bug then please open a new issue with a sample project that reproduces the issue (ideally without using lombok). I'm not sure why you think the parsing of application.properties should fail, we'll need more details if you do open an issue.

in fact it gets doubly confusing because on one hand the documentation says to use @NestedConfigurationProperty and elsewhere the documentation says: This annotation has no bearing on the actual binding processes

You should use the annotation to ensure that the correct meta-data is generated so that IDE auto-completion works. The annotation isn't actually needed for Spring Boot to perform the binding at runtime.

— Reply to this email directly, view it on GitHub https://github.com/spring-projects/spring-boot/issues/33239#issuecomment-2130619140, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6NWEKZKQI3L5B2RKHE2PD3ZD7OCHAVCNFSM6AAAAAASDLOZKSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZQGYYTSMJUGA . You are receiving this because you were mentioned.Message ID: @.***>

Comment From: bclozel

IDEs use the metadata generated by Spring Boot to provide auto-completion when typing in application.properties files.

Please stop commenting here and provide the requested sample in a new issue.