How to autowire Spring @ConfigurationProperties nested objects

Viewed 149

When using Spring Boot @ConfigurationProperties binding, is it possible to autowire nested objects (i.e. make them a prototype bean). This would allow auto-config to instantiate a Domain Model instead of just some data beans that require further post-processing.

If post-processing is required, what is the best way to get Spring to post-process an object (as opposed to user doing it manually in each case).

Adapting Spring's documented example:

@ConfigurationProperties("my.service")
public class MyProperties {

    private List<Security> security;

    // getters / setters...

    @Scope("prototype") // FIXME elevate this class into a bean ...
    public static class Security {
    
        @Autowired // ... such that basic stuff like this works
        private MyService service;
        
        private String username;
        private String password;
    }

(Spring Boot 2.5.3)

0 Answers
Related