WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext()); TestService testService= (TestService) wac.getBean("TestService");
获取ApplicationContext.xml中的bean
BeanFactory factory = new ClassPathXmlApplicationContext("classpath:/applicationContext*.xml"); ITestService testService = (ITestService)factory.getBean("test-service");