@Component public class SpringApplicationContextHolder implements ApplicationContextAware { private static ApplicationContext applicationContext; @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { SpringApplicationContextHolder.applicationContext(applicationContext); } public static void applicationContext(ApplicationContext applicationContext) { SpringApplicationContextHolder.applicationContext = applicationContext; } public static ApplicationContext applicationContext() { return applicationContext; } }
使用:
SpringApplicationContextHolder.applicationContext().getBean(ExcelTemplateMapper.class);
标签:applicationContext,管理,SpringApplicationContextHolder,spring,static,ApplicationCo From: https://www.cnblogs.com/wxynb/p/17860272.html