标签:
Container的实现类是ContainerImpl
首先只看一部分 看他的属性和其中一个构造函数
final Map<Key<?>, InternalFactory<?>> factories; final Map<Class<?>, Set<String>> factoryNamesByType; ContainerImpl( Map<Key<?>, InternalFactory<?>> factories ) { this.factories = factories; Map<Class<?>, Set<String>> map = new HashMap<Class<?>, Set<String>>(); for ( Key<?> key : factories.keySet() ) { Set<String> names = map.get(key.getType()); if (names == null) { names = new HashSet<String>(); map.put(key.getType(), names); } names.add(key.getName()); } for ( Entry<Class<?>, Set<String>> entry : map.entrySet() ) { entry.setValue(Collections.unmodifiableSet(entry.getValue())); } this.factoryNamesByType = Collections.unmodifiableMap(map); }
<bean type="com.service.UserService" name="service1" class="com.service.impl.UserServiceImp1" /> <bean type="com.service.UserService" name="service2" class="com.service.impl.UserServiceImp2" />
factories就是所有构造bean的工厂 要构造什么bean就找对应的工厂构造
怎么得到工厂?用key key是之后会看到 Key.newInstance(type, name) type和name就是struts.xml配置的信息
然后factoryNamesByType就是一个type对应多个name
标签:
原文地址:http://blog.csdn.net/u011686226/article/details/45850095