获取 Spring 应用上下文
使用工具类
如果你的项目中有一个工具类实现了 ApplicationContextAware
接口,如 cn.shutdown.pf.utils.SpringContextUtils
,可以使用该类获取 ApplicationContext
:
@Component
public final class SpringContextUtils implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
SpringContextUtils.applicationCo