- 应用
- InitialzingBean用法
1.接口继承InitialzingBean
2.重写afterPropertiesSet方法,将实现类放到ConcurrentHashMap中,
3.使用时根据key调用对应服务
demo:
@Override
public void afterPropertiesSet() throws Exception {
xxContext.xxset(xxkey, this);
}
public class ExternalAssertServiceContext {
private final static Map MAP = new ConcurrentHashMap<>();
public static IxxService getxxService(Integer xxkey){
IxxService ixxService = MAP.get(xxkey);
return ixxService;
}
public static void xxset(Integer xxkey, IxxService service){
MAP.put(xxkey, service);
}
}
if(xxkey != null && xxContext.getInvestorService(xxkey)!= null) {
xxContext.getInvestorService(xxkey).xxMethod();
}
InitialzingBean用法
当一个类实现这个接口之后,Spring启动后,初始化Bean时,若该Bean实现InitialzingBean接口,会自动调用afterPropertiesSet()方法,完成一些用户自定义的初始化操作。



