简体   繁体   中英

Spring can't load xml configuration file

This error blows my brain. All the junit tests is fine but when my application loads as plugin for another application I have an errors. The beans.xml is 100% at root of jar file but for some reason the main application, that loads my plugin can't find the file. Why?

In my application's boot method I call new ClassPathXmlApplicationContext("beans.xml"); throws

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

or

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

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: The problem was the application uses custom classloader that does not load resource files in root, META-INF and etc. but only classes

The FileNotFoundException that you get really points out that the beans.xml file is not in your jar at the place where you think it is. I would have a look inside that jar. You can for example open the jar with the 7-zip tool . I find that this provides useful insight when you get errors like the one you report.

If you're getting the FileNotFoundException it is because the file is not located where you're looking for it. The beans.xml file must be located in src/main/resources

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM