1、 SpringContextHolder方法
public class SpringContextHolder implements ApplicationContextAware {
private static ApplicationContext context;
@Override
public void setApplicationContext(ApplicationContext context)throws BeansException {
SpringContextHolder.context = context;
}
public static ApplicationContext getContext(){
return context;
}
public static Object getBean(String beanName) {
return context.getBean(beanName);
}
}
2、使用实例
JedisPool jedisPool = (JedisPool) SpringContextHolder.getBean("jedisPool");