@Component public class SpringContextUtil implements BeanFactoryAware { private static BeanFactory beanFactory; private final static Logger LOG = LoggerFactory.getLogger(SpringContextUtil.class); @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { SpringContextUtil.beanFactory = beanFactory; } public static <T> T getBean(String beanName) { if (null != beanFactory) { return (T) beanFactory.getBean(beanName); } return null; } }