[英]Spring Batch CommandLineJobRunner can't find .xml configuration file
[英]Spring can't load xml configuration file
這個錯誤使我震驚。 所有的junit測試都很好,但是當我的應用程序作為另一個應用程序的插件加載時,我遇到了錯誤。 beans.xml是jar文件根目錄的100%,但是由於某種原因,加載我的插件的主應用程序找不到該文件。 為什么?
在應用程序的啟動方法中,我調用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:問題在於應用程序使用自定義類加載器,該類加載器不加載根目錄,META-INF等中的資源文件,而僅加載類
您實際上得到的FileNotFoundException指出,beans.xml文件不在您認為存在的位置的jar中。 我去看看那個罐子。 例如,您可以使用7-zip工具打開罐子。 我發現當您報告錯誤時,這提供了有用的見解。
如果您收到FileNotFoundException
那是因為該文件不在您要查找的位置。 beans.xml
文件必須位於src/main/resources
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.