org.springframework.web.context.support.WebApplicationContextUtils
它有一个static的方法getWebApplicationContext(ServletContext sc)
可以使我们得到一个ApplicationContext的引用,
但这个方法有一个参数ServletContext,它是Servlet容器提供的上下文,在非Servlet环境下是得不到的。
我们可以定义一个servlet,该servlet配置为被容器第一个加载,它可以得到ServletContext,从而得到ApplicationContext的引用,
我们再把这个引用保存在一个所用应用都能访问到的地方。
比如:在SearchContentController里
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(request.getServletContext());
Reg reg = (Reg)ac.getBean("regAction");
2.project---->properties---->libraries---->Add Library---->Server Runtime
联系客服