2015-09-15 155 views
0

這個錯誤使我的大腦受到了打擊。所有的junit測試都很好,但是當我的應用程序加載爲另一個應用程序的插件時,我有一個錯誤。 beans.xml在jar文件的根目錄下爲100%,但由於某種原因,加載我的插件的主應用程序找不到該文件。爲什麼?Spring無法加載xml配置文件

在我的應用程序的啓動方法,我稱之爲 new ClassPathXmlApplicationContext("beans.xml");拋出

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [beans.xml]; nested exception is java.io.FileNotFoundException: class path resource [beans.xml] cannot be opened because it does not exist

new FileSystemXmlApplicationContext(getClass().getClassLoader().getResource("beans.xml").getPath());拋出

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:/C:/path/to/my.jar!/beans.xml]; nested exception is java.io.FileNotFoundException: C:\path\to\my.jar!\beans.xml (The system cannot find the path specified)


UPD:問題是應用程序使用定製ClassLoader並不在根加載資源文件,META-INF等,但只有類

+0

你是什麼意思的'jar文件的根',你可以檢查它位於什麼路徑? –

+0

@Jama我的意思是位於jar文件中的beans.xml,因爲它必須是。 – TeroBlaZe

回答

1

,你得到真正指出,在beans.xml文件中的FileNotFoundException異常不在你認爲它的位置。我會看看那個罐子裏面。你可以舉個例子打開罐子with the 7-zip tool。我發現當你得到像你所報告的錯誤時,這提供了有用的見解。

1

如果您得到FileNotFoundException,這是因爲該文件不在您要查找的位置。 beans.xml文件必須位於src/main/resources

+0

是的,它在那裏 – TeroBlaZe