Java获取spring注解bean

[b]获取注释方式(Annotaction)的bean[/b]

WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());   
TestService testService= (TestService) wac.getBean("TestService");


[b]获取ApplicationContext.xml中的bean[/b]

BeanFactory factory = new ClassPathXmlApplicationContext("classpath:/applicationContext*.xml");  

ITestService testService = (ITestService)factory.getBean("test-service");

你可能感兴趣的:(spring)