首页 > 解决方案 > Spring - 类路径资源X无法打开,因为它不存在

问题描述

我有一个我无法解决的问题!我用谷歌搜索了几个小时,但我没有找到任何解决方案......我有这个:

消费者上下文.xml

以及加载此 xml 资源 (consumerContext.xml) 的文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans ...>

<!-- Inclusion d'autres fichiers de contexte Spring -->
<import resource="classpath:/org/example/demo/ticket/consumer/consumerContext.xml" />
<import resource="classpath:/org/example/demo/ticket/business/businessContext.xml" />
<import resource="classpath:/org/example/demo/ticket/webapp/webappContext.xml" />

</beans>

我正在使用 Maven 并且 src/main/resources 在类路径中。

我总是并且总是错误:

class path resource [org/example/demo/ticket/consumer/consumerContext.xml] cannot be opened because it does not exist

有人有想法吗?

感谢提前(对不起我的英语......)

标签: springmavenresources

解决方案


我认为问题在于,您没有将 consumerContext.xml 放在 org/example/demo/ticket/consumer/ 中。

要解决这个问题:

1)将consumerContext.xml和其他xml直接放在src/resources

2) 改变

<import resource="classpath:/org/example/demo/ticket/consumer/consumerContext.xml" />

<import resource="classpath:consumerContext.xml" />

推荐阅读