简体   繁体   English

找不到外部jar的Spring配置* .xml文件

[英]External jar's Spring configuration *.xml file is not found

I have a jar x which has a class like 我有一个x罐子

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
@Configuration
@ImportResource({ "/WEB-INF/assembly/appconfig.xml" })
public class DSPPlatformCommonSiteDefConfig {}

Now in a different project altogether, I have added this jar as a dependency. 现在,在另一个项目中,我已将此罐子添加为依赖项。

And import this class like: 并导入此类,例如:

@Configuration
@Import(DSPPlatformCommonSiteDefConfig.class)
public class ApplicationConfiguration {

} }

So basically, I am using Spring configuration file of a jar in my project. 因此,基本上,我在项目中使用的是jar的Spring配置文件。

But when I run my application I get this error: 但是,当我运行我的应用程序时,出现此错误:

Message: java.io.FileNotFoundException: class path resource [WEB-INF/assembly/appconfig.xml] cannot be opened because it does not exist org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [WEB-INF/assembly/appconfig.xml]; 消息:java.io.FileNotFoundException:无法打开类路径资源[WEB-INF / assembly / appconfig.xml],因为它不存在org.springframework.beans.factory.BeanDefinitionStoreException:IOException从类路径资源[WEB解析XML文档-INF / assembly / appconfig.xml]; nested exception is java.io.FileNotFoundException: class path resource [WEB-INF/assembly/appconfig.xml] cannot be opened because it does not exist 嵌套的异常为java.io.FileNotFoundException:类路径资源[WEB-INF / assembly / appconfig.xml]无法打开,因为它不存在

I do not understand why it is looking in the classpath. 我不明白为什么它在类路径中查找。 And even if it does, the jar IS in my classpath. 即使这样做,jar也位于我的类路径中。

Your problem seems to be at the path declaration for the location inside the @ImportResource annotation. 您的问题似乎出在@ImportResource批注内的位置的路径声明中。 The path should be the URI of the file which must not be the one that you declared. 路径应该是文件的URI,该URI不能是您声明的URI。

An example could be the following path: 一个示例可能是以下路径:

@ImportResource(locations={ "file:com/yourProjectName/assembly/appconfig.xml" })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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