2016-10-06 4 views
3

の地図を注入、私は以下の設定を使用してマップ注入しています -春注釈 - XMLアノテーションを使用したオブジェクト

<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> 

私は3つの豆作成している - DefaultImpl、PersonImplとCompanyImplを。 Spring Annotationを使用してこれらをマップとして挿入するにはどうすればよいですか?

EDIT:今のところ、私は(Javaのコンフィグを使用し)以下ではなく、必ずそれが推奨されるアプローチであれば

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);   
} 

答えて

関連する問題