1. 获取ApplicationContext.xml中的bean
BeanFactory factory = new ClassPathXmlApplicationContext("classpath:/applicationContext.xml");TestService testService = (TestService)factory.getBean("testService");
2. 获取注解方式中的bean
WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();TestService testService = (TestService)wac.getBean("testService");