首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

java种和servlet中访问spring中的bean

2012-11-11 
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的名字");

热点排行