2018-04-16 16:02
@shigy_007
public class BeanFactory implements ApplicationContextAware {
private static ApplicationContext ctx;
public static Object getBean(String name) {
return ctx.getBean(name);
}
public static T getBean(Class requiredType) {
return ctx.getBean(requiredType);
}
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
ctx = applicationContext;
}
}
在spring配置里定义BeanFactory即可,