java种和servlet中访问spring中的bean

java类和servlet中访问spring中的beanservlet 的访问spring中的bean:??? ServletContext applicationnull

java类和servlet中访问spring中的bean

servlet 的访问spring中的bean:

??? ServletContext application=null;
??? WebApplicationContext wac=null;
??? application = getServletContext();
??? wac = WebApplicationContextUtils.getWebApplicationContext(application);

??? wac.getBean("bean的名字");

java 类访问spring 中的bean:

?? ??? ApplicationContext context = new ClassPathXmlApplicationContext(
??? ??? ??? ??? "com/appdev/gps/test-applicationContexts.xml");//路径从根目录下写起
??? ??? context.getBean("bean的名字");