方式一:web容器运行时获取
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); Two two = (Two)ctx.getBean("twoService");
方式二:
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring/beans.xml"); Two two = (Two)ctx.getBean("twoService");
时间: 2024-10-05 17:10:53