属于新手,学校J2EE开发,在学到Spring时,书上的一个实例遇到了一点小诡异事件,求真相!
开发工具elipse,jdk1.60,spring版本2.5.6,web.xml中的内容:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>12.3</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <!--设置自动加载配置文件-->
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value> </init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>,
index.jsp中的内容
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaBean的注入</title>
</head>
<body>
<a href="http://localhost:8080/12.3/main.do">执行JavaBean的注入</a>
</body>
</html>,
运行报错:rg.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/applicationContext.xml]
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:349),这里仅贴出了主要部分,问题也出现在这部分。
网上找了好多资料,确认文件名没有写错,网上参考myelicpse中的解决办法!也属无奈之举!
将web.xml中颜色部分内容改为
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
然后将applicationContext.xml考入classes文件夹中,No problem!吓死俺了,求真相~~~不盛感激

解决方案 »

  1.   

    因为你在做开发的时候 applicationContext.xml 放的位置是 src 目录下的
    这个目录对应着项目部署之后的路径就是 >/WEB-INF/classes/applicationContext.xml
      

  2.   

    楼上正解,书上的配置文件是放到web-inf目录下的,所以那样写,而你的是放到src目录下,编译之后就到web-inf/classes目录下了。还有种写法就是
    classpath:applicationContext.xml,表示在生成代码目录下的文件
      

  3.   

    <param-value>classpath:applicationContext.xml</param-value>
      

  4.   

    这个你要看看你的eclipse的设置的编译目录是什么,把该文件放到你的编译目录中就可以了。
    具体设置:
    1.打开工程,右键属性
    2.找到build path,查看“Source”目录下的“ Default output folder”选项,放到对应的目录下即可。