Using the @EnableConfigurationProperties annotation

The @EnableConfigurationProperties annotation in the configuration class specifies and auto-injects the container bean. Let's see the following configuration class file:

@Configuration 
@EnableConfigurationProperties(ConnectionSettings.class) 
public class AccountsClientConfiguration { 
   // Spring initialized this automatically 
   @Autowired  
   ConnectionSettings connectionSettings; 
 
   @Bean  
   public AccountClient accountClient() { 
         return new AccountClient( 
               connectionSettings.getHost(), 
               connectionSettings.getPort(),  
               ... 
         ); 
   } 
}

This is often unnecessary, however, because all of the configuration classes behind Spring Boot auto-configuration are already annotated with @EnableConfigurationProperties.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset