1. @Configuration
    2. public class SpringContextUtil implements ApplicationContextAware {
    3. private static ApplicationContext applicationContext;
    4. @Override
    5. public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    6. SpringContextUtil.applicationContext = applicationContext;
    7. }
    8. public static ApplicationContext getCtx() {
    9. return SpringContextUtil.applicationContext;
    10. }
    11. public static <T> T getBean(Class<T> t) {
    12. return SpringContextUtil.applicationContext.getBean(t);
    13. }
    14. }