1、@Controller、@Service、@Component三个注解没有加载先后顺序之分(根据构造方法的执行顺序得出,不确定其真实性),只根据类名a-z顺序执行。
2、工厂模式时,想要将实现类放到static Map集合中,要通过构造器的方式将Spring注入到里面才可以获取到对象地址,否则是注入不进去的,至少目前没发现其他方法。。
@Component
public class SingleFactory {
private static Map<String, SingleService> map;
public SingleFactory(Impl01 impl01, Impl02 impl02) {
map = new HashMap<String, SingleService>() {{
put("impl01", impl01);
put("impl02", impl02);
}};
}
public static SingleService getSingleImpl(String type){
return map.get(type);
}
}