'How to define a @Qualifier value from config file?

Case:

@Autowired
@Qualifier("${value_from_config_file}")
A a;

config file:
value_from_config_file = a

just like:

@Autowired
@Qualifier("a")
A a;

However I failed with @Qualifier("${value_from_config_file}").

How to implement this kind of requirement? Or dynamic get a bean from config file indication.



Solution 1:[1]

Define a configuration class like "AppConfig". Put "${value_from_config_file}" as "someValue" field in this class with a getter. Then write a public method which returns "someValue" as result. put @Bean on the top of the method with a given name. Then use this bean name as your @Qualifier

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Azadi Yazdani