ITeye博客

Java获取spring注解bean

youchengLin · 2015-06-12 17:13 · spring · 企业架构 · Markdown

获取注释方式(Annotaction)的bean

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"); 

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。