一、注解的bean
1、
ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
WorkContentService workContentService = (WorkContentService) ac.getBean("workContentServiceImpl");
2、
WebApplicationContext wac = ContextLoader.getCurrentWebApplicationContext();
WorkContentService workContentService = (WorkContentService) wac.getBean("workContentServiceImpl");
二、xml配置的bean
1、
ClassPathXmlApplicationContext beanFac = new ClassPathXmlApplicationContext(“classpath:serviceImpl.xml”);
WorkContentService workContentService = (WorkContentService) beanFac.getBean(“workContentServiceImpl”)
2、
ApplicationContext ac1 = new FileSystemXmlApplicationContext("com/spark/system/serviceImpl.xml");
WorkContentService workContentService = (WorkContentService)ac1.getBean("workContentServiceImpl");