获取bean的三种方法

来源:互联网 发布:jdk环境变量 linux 编辑:程序博客网 时间:2024/05/22 19:26

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