[转载]Spring加载配置文件的几种方法(org.springframework
1个回答
展开全部
FileSystemXmlApplicationContext("WebContent/WEB-INF/config/spring/web-application-config.xml"); 那么在触发action时会报错: javax.servlet.ServletException: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from file [D:Program Filesapache-tomcat-6.0.26binWebContentWEB-INFconfigspringweb-application-config.xml]; nested exception is java.io.FileNotFoundException: WebContentWEB-INFconfigspringweb-application-config.xml (The system cannot find the path specified) 如果改为: ApplicationContext ctx=new
ClassPathXmlApplicationContext("WebContent/WEB-INF/config/spring/web-application-config.xml"); 又会报错: javax.servlet.ServletException: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [WebContent/WEB-INF/config/spring/web-application-config.xml]; nested exception is java.io.FileNotFoundException: class path resource [WebContent/WEB-INF/config/spring/web-application-config.xml] cannot be opened because it does not exist 这是因为调用的是ClassPathXmlApplicationContext,而WebContent/WEB-INF/config/spring/web-application-config.xml并不在classespath路径中。
ClassPathXmlApplicationContext("WebContent/WEB-INF/config/spring/web-application-config.xml"); 又会报错: javax.servlet.ServletException: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [WebContent/WEB-INF/config/spring/web-application-config.xml]; nested exception is java.io.FileNotFoundException: class path resource [WebContent/WEB-INF/config/spring/web-application-config.xml] cannot be opened because it does not exist 这是因为调用的是ClassPathXmlApplicationContext,而WebContent/WEB-INF/config/spring/web-application-config.xml并不在classespath路径中。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询