Injecting Properies in Spring boot
In this tutorial, we will find how to bind configuration properties to Structured Object.
Spring Boot allows you to externalize your configuration so you can work with the same application code in different environments. If these configurations are all related then we can bound these to java object using spring's @ConfigurationProperties annotation.
Spring Boot allows you to externalize your configuration so you can work with the same application code in different environments. If these configurations are all related then we can bound these to java object using spring's @ConfigurationProperties annotation.
Ways to make configuration object injected into application
- Annotate Application class with @EnableConfigurationProperties(value=MyProperties.class). In this case, there is no need to mark your configuration object with @Component annotation.
- Or mark your configuration object with @Component annotation. This will make your class to be picked up by Spring's component scanner.
Comments
Post a Comment