1)通过session获取spring上下文:
ServletContext context = request.getSession().getServletContext();
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
yourService = (YourService)ctx.getBean("yourService");
本文介绍了一种通过session来获取Spring应用上下文的方法。具体步骤包括使用HttpServletRequest对象获取ServletContext,然后利用WebApplicationContextUtils工具类从ServletContext中得到WebApplicationContext,最后通过该上下文获取所需的业务服务Bean。
1)通过session获取spring上下文:
ServletContext context = request.getSession().getServletContext();
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(context);
yourService = (YourService)ctx.getBean("yourService");
486

被折叠的 条评论
为什么被折叠?