1. 程式人生 > >java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist

java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist

java ... mod ons exc pen 方法 except open

java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist 
異常如下:
java.io.FileNotFoundException: class path resource [com/jxust/zjh/model/Account.hbm.xml] cannot be opened because it does not exist

在spring中我這樣配置<property name="mappingResources">
<list> <value>com/jxust/zjh/model/Account.hbm.xml</value>
</list>
</property>
就報上述錯誤,Account.hbm.xml確實在此目錄下。
但是,我改成這樣就運行正常,
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/jxust/zjh/model/</value>
</list>
</property>





解決方案:
1.路徑問題,,,,,,直接將配置文件搞到src下面.....因為myeclipse默認會去src下找

最簡單的方法還是老老實實把xml放在src下方便。

或者建立config時建立成source folder,,,,就相當於是classpath了


2.此時去查看tomcat中的web-inf下的classes文件夾,查看上面報錯的差找不到beans文件是否存在於tomcat中....如果不存在,,,,說明原因在這裏

此時需要將tomcat中部署的項目刪掉.然後在myeclipse中的項目工程clean一下,然後重新部署,會發現所有文件都部署到了tomcat中,項目完美運行.

  

java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist