
正文
tomcat启动后,在普通java类中获取spring管理的bean和ServletContext,(经过验证,可以取到)
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
//从spring容易中获取beanpublic static Object getBean(String beanName){ApplicationContext context = ContextLoader.getCurrentWebApplicationContext();return context.getBean(beanName);}//获取ServletContextpublic static ServletContext getServletContext(){WebApplicationContext context = ContextLoader.getCurrentWebApplicationContext();return context.getServletContext();}







