Using XML annotation , I am injecting a map using the below config -
<bean id = "customerfactory" class = "com.brightstar.CustomerFactory"> <property name = "getCustomerMap"> <map key-type = "java.lang.String" value-type = "com.brightstar.CustomerImpl"> <entry key = "DEFAULT" value-ref = "getDefaultImpl"></entry> <entry key = "PERSON" value-ref = "getPersonImpl"></entry> <entry key = "COMPANY" value-ref = "getCompanyImpl"></entry> </map> </property> </bean> I have created 3 beans - DefaultImpl , PersonImpl and CompanyImpl. How can I inject these as a map using Spring Annotation?
EDIT: For now , I have performed the below but not sure if it is the recommended approach
private Map<String, CustomerImpl> getCustomerMap ; @Autowired private GetDefaultImpl getDefaultImpl; @Autowired private GetPersonImpl getPersonImpl; @Autowired private GetCompanyImpl getCompanyImpl; private static final String DEFAULT = "DEFAULT"; private static final String COM = "PERSON"; private static final String SOM = "COMPANY"; @PostConstruct public void init(){ getCustomerMap = new LinkedHashMap<String,CustomerImpl>(); getCustomerMap.put(DEFAULT, getDefaultImpl); getCustomerMap.put(PERSON, getPersonImpl); getCustomerMap.put(COMPANY, getCompanyImpl); }