java外部jar的Spring配置*。找不到xml文件
我有一个jar x,它的类是
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
@Configuration
@ImportResource({ "/WEB-INF/assembly/appconfig.xml" })
public class DSPPlatformCommonSiteDefConfig {}
现在在一个完全不同的项目中,我添加了这个jar作为依赖项
然后像这样导入这个类:
@Configuration
@Import(DSPPlatformCommonSiteDefConfig.class)
public class ApplicationConfiguration {
}
基本上,我在项目中使用了jar的Spring配置文件
但当我运行我的应用程序时,我会出现以下错误:
信息:java。伊奥。FileNotFoundException:无法打开类路径资源[WEB-INF/assembly/appconfig.xml],因为它不存在 组织。springframework。豆。工厂BeanDefinitionStoreException:IOException解析来自类路径资源[WEB-INF/assembly/appconfig.XML]的XML文档;嵌套的例外是java。伊奥。FileNotFoundException:无法打开类路径资源[WEB-INF/assembly/appconfig.xml],因为它不存在
我不明白它为什么在类路径中寻找。即使有,jar也在我的类路径中
# 1 楼答案
您的问题似乎出现在
@ImportResource
注释中location的路径声明上。路径应该是文件的URI,而不是您声明的那个一个例子可以是以下路径: