edit-icon download-icon

Inject configuration

Last Updated: Apr 20, 2018

Use the Spring MVC annotation to inject the configurations and reduce configuration management costs.

The @Value can be used directly to inject the configurations:

  1. @Component
  2. class SampleRunner implements ApplicationRunner {
  3. @Value("${user.id}")
  4. String userId;
  5. @Value("${user.name}")
  6. String userName;
  7. @Value("${user.age}")
  8. int userAge;
  9. @Override
  10. public void run(ApplicationArguments args){
  11. System.out.println(userId);
  12. System.out.println(userName);
  13. System.out.println(userAge);
  14. }
  15. }

Note: If the same key is configured in application.properties of the Spring Boot application and ${spring.application.group}:${spring.application.name}.properties of ACM at the same time, the value in ACM overrides the default value of the application.

Thank you! We've received your feedback.