获取bean的三种方法

1.spring容器注入bean


2.WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationConte(servletContext);


ServiceName serviceName = context.getBean("serviceName");


3.ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
  ServiceName serviceName = context.getBean("serviceName");

你可能感兴趣的:(note)