未找到 Spring 配置
我的 web.xml 中有以下内容:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
我有 2 个文件:
- 中的 web.xml applicationContext-service.xml 旁边的 WEB-INF 中的 applicationContext-web.xml
- myapp-service.jar
部署应用程序时,我得到一个
找不到依赖项的 [AServiceBean] 类型的匹配 bean:预期 至少 1 个有资格作为自动装配候选者的 bean 依赖性。
似乎没有找到 applicationContext-service.xml 。如果我将其复制到 web.xml 旁边,它就可以正常工作。我不明白为什么会发生这种情况。
服务器是 Tomcat 6。
感谢任何帮助。 谢谢。
编辑
澄清一下:如果我使用
<param-value>
classpath:applicationContext-web.xml,
classpath:applicationContext-service.xml
</param-value>
应用程序部署没有任何问题,那么这只是查找(或不查找)applicationContext-service.xml 的问题
I have the following in my web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>
I have 2 files:
- applicationContext-web.xml in the WEB-INF next to the web.xml
- applicationContext-service.xml in the myapp-service.jar
When deploying the app, I get a
No matching bean of type [AServiceBean] found for dependency: expected
at least 1 bean which qualifies as autowire candidate for this
dependency.
Seems like the applicationContext-service.xml is not found. If I copy it next to the web.xml, it works fine. I can't figure out why this happens.
The server is a Tomcat 6.
Any help is appreciated.
Thanks.
EDIT
For clarification: if I use
<param-value>
classpath:applicationContext-web.xml,
classpath:applicationContext-service.xml
</param-value>
the app deploys without any issue, so it's just a matter of finding (or not finding) the applicationContext-service.xml
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
classpath*:applicationContext-*.xml
(冒号前有星号)。然而它可能不起作用,例如JBoss有问题,要使其工作你需要使用jboss的一些特殊的类加载器。
另外,还有一些 在根中使用模式的问题。
无论如何,我建议避免使用模式,最好使用两个显式的
import
语句创建一个applicationContext.xml
。Try to use
classpath*:applicationContext-*.xml
(there is asterisk before the colon).However it may not work, e.g. JBoss has problems, to make it work you need use some special class loader from jboss.
Also, there are some problems using patterns in root.
Anyway I would recommend avoid patterns, better to make an
applicationContext.xml
with two explicitimport
statements.您需要将配置文件放入类路径中。
或者与此类似的东西将它们保留在一个地方
applicationContext-service.xml :如果它已经在 jar 文件中,则不需要复制它
示例 main-config.xml
You need to place your config files into the classpath.
or sth similar to this to keep them in one place
applicationContext-service.xml : You dont need to copy this one if it is already in the jar file
Sample main-config.xml