1.在初始化时保存ApplicationContext对象
2.通过Spring提供的utils类获取ApplicationContext对象
3.继承自抽象类ApplicationObjectSupport
4.继承自抽象类WebApplicationObjectSupport
5.实现接口ApplicationContextAware
6.通过Spring提供的ContextLoader
来说一下实现接口的方法:
@Component public class example implements ApplicationContextAware { private static ApplicationContext context; @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { context = applicationContext; } example(){ } public static TypeHandler createHandler(Type type) throws Exception{ if(type==null){ throw new Exception("handler type is null"); } return (TypeHandler) context.getBean(type.getShortName()+"Handler"); } } |
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系51Testing小编(021-64471599-8017),我们将立即处理