/**
* 为不是spring所管理的对象,需要引用spring管理对象的时候所用的工具类
* @author he_guanhong
*
*/
public class SpringApplicationContext implements ApplicationContextAware{
protected static ApplicationContext context;
@Override
public void setApplicationContext(
org.springframework.context.ApplicationContext applicationContext)
throws BeansException {
// TODO Auto-generated method stub
context = (ApplicationContext) applicationContext;
}
public static ApplicationContext getContext() {
return context;
}
//MyBean myBean = (MyBean) SpringApplicationContext.getContext().getBean("myBean");
}
在其他类中使用:
TSAService tsaService = SpringApplicationContext.getContext().getBean(TSAService.class);