1、FileSystemXmlApplicationContext是从文件绝对路径加载配置文件
ApplicationContext ctx=new FileSystemXmlApplicationContext( "G:/Test/applicationcontext.xml ");
2、ClassPathXmlApplicationContext是从classpath下加载配置文件(适合于相对路径方式加载)
ApplicationContext ctx=new ClassPathXmlApplicationContext( "/WEB-INF/classes/applicationcontext.xml ");
3、XmlWebApplicationContext是专为web工程定制的
ServletContext servletContext = request.getSession().getServletContext();
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext );
楼主的既然是一个web项目,那么建议用第三种方式加载
ApplicationContext context = new FileSystemXmlApplicationContext我也不喜欢用这个.感觉确实有点麻烦.
ApplicationContext context = new FileSystemXmlApplicationContext( "classpath:applicationContext.xml ");