获取当前的spring容器ApplicationContext 。
方法一:(获取当前的spring容器,任何java类中适用) ServletContext application = ServletActionContext.getServletContext(); ApplicationContext act = ContextLoader.getCurrentWebApplicationContext()
·
方法一:(获取当前的spring容器,任何java类中适用)
ServletContext application = ServletActionContext.getServletContext();
ApplicationContext act = ContextLoader.getCurrentWebApplicationContext();UserService userService = (UserService) act.getBean("userService");
方法二:(重新加载spring容器)
ApplicationContext ac = new FileSystemXmlApplicationContext("applicationContext.xml");
方法三:(通过request或session加载spring容器)
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
更多推荐
已为社区贡献2条内容
所有评论(0)