==
==
@Component
public class ApplicationContextHandle implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
ApplicationContextHandle.applicationContext = applicationContext;
}
/**
* 获取对象 这里重写了bean方法,起主要作用
*
* @param name
* @return Object 一个以所给名字注册的bean的实例
* @throws BeansException
*/
public static Object getBean(String name) throws BeansException {
return applicationContext.getBean(name);
}
}
==