Spring 在普通java类中调用Sprng容器对象,手动注入获取bean,注释方式,Annotaction

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


获取注释方式(Annotaction)的bean
WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext()); 
TestService testService= (TestService) wac.getBean("TestService");


黑色头发:http://heisetoufa.iteye.com/

你可能感兴趣的:(bean,beanfactory,factory)