如何在线程中获取spring 管理的bean

WebApplicationContext webApplication = ContextLoader.getCurrentWebApplicationContext();

this.messageRemindInfoDAO = webApplication.getBean(MessageRemindInfoDAO.class);













implements ApplicationContextAware

private static ApplicationContext context;


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }


    public static ApplicationContext getContext(){
        return context;
    }


    public static Object getBean(String beanName) {
        return context.getBean(beanName);
    }

posted @ 2022-09-23 18:03  silentmuh  阅读(62)  评论(0编辑  收藏  举报
Live2D