Is there any way to get @Qualifier name from each bean of @Autowired List<Bean> in Spring. Or more broadly: Can i get a Bean @Qualifier information at runtime if i have a bean instance?
Lets suppose i have:
//Config.java
@Bean(name = "en-db")
@ConfigurationProperties(prefix = "spring.datasource.en")
public DataSource dataSourceEN() {...}
@Bean(name = "de-db")
@ConfigurationProperties(prefix = "spring.datasource.de")
public DataSource dataSourceDE() {...}
//Repository.java
public Repository(List<DataSource> ds) {
// Is there any way to create a hashmap of Qualifier => Bean?
// like {"en-db" : ds.get(0), "de-db" : ds.get(1)}
// or maybe there is a way to autowire the Hashmap<Qualifier, Bean>
}
right now i'm using this (and it works fine):
public Repository(@Qualifier("en-db") DataSource en,
@Qualifier("de-db") DataSource de, //... and many more
){
Map<String, EntityManager> dataSources = new HashMap<>();
dataSources.put("en-db", en);
dataSources.put("de-db", de);
...
}
But i have 10+ data sources and it feels that there should be some way to detect the Bean Qualifier even after autowire and i can just use @Autowired List.
PS: it is not a localisation issue, i'm using all 10 db on a single page