spring-cfg.xml文件配置:
<bean id="iAlarmHandlerInfoMap" class="com.boco.cfg.IAlarmHandlerInfoMap" scope="prototype">
<property name="mapping">
<map>
<entry key="slaPreAlarmHandlerInfo">
<bean class="com.boco.impl.AlarmHandlerInfoImpl"></bean>
</entry>
</map>
</property>
</bean>
映射配置文件的的Map对象:
public class IAlarmHandlerInfoMap {
private Map<String, IAlarmHandlerInfo> mapping;
public Map<String, IAlarmHandlerInfo> getMapping() {
return mapping;
}
public void setMapping(Map<String, IAlarmHandlerInfo> mapping) {
this.mapping = mapping;
}
}
通过map注入获取对应的类实例:
className============"slaPreAlarmHandlerInfo"
public IAlarmHandlerInfo getIAlarmHandlerInfoByClassName(String className){
IAlarmHandlerInfo alarmHandler = null;
if(className != null){
IAlarmHandlerInfoMap iaphMap = (IAlarmHandlerInfoMap)util.getBean("iAlarmHandlerInfoMap");
alarmHandler = iaphMap.getMapping().get(className);
}else{
log.error("输入的类名称为空!");
}
alarmHandler.setSubClassName(className);//返回对象前将实例化子类类名设置好
return alarmHandler;
}