🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
##### 获取spring 的bean 方法总结 一. 实现ApplicationContextAware\(适用于springboot\) ``` @Configuration public class AppContextUtil implements ApplicationContextAware { private static ApplicationContext ctx; public static Object getBean(String name) { return ctx.getBean(name); } public static void setCtx(ApplicationContext ctx) { AppContextUtil.ctx = ctx; } @Override public void setApplicationContext(ApplicationContext context) throws BeansException { AppContextUtil.ctx = context; } } ``` 二. 获取ApplicationContext的方法 ``` ApplicationContext applicationContext = new FileSystemXmlApplicationContext("applicationContext.xml"); ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml"); ``` 三. 继承自抽象类ApplicationObjectSupport 四. 继承自抽象类WebApplicationObjectSupport