未找到 Spring 配置

发布于 2024-12-19 13:58:54 字数 924 浏览 7 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

缱绻入梦 2024-12-26 13:58:54

尝试使用 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 explicit import statements.

笑忘罢 2024-12-26 13:58:54

您需要将配置文件放入类路径中。

WEB-INF/classess  is the directory you need to place your configuration files
classpath:applicationContext-*.xml will then work

或者与此类似的东西将它们保留在一个地方

WEB-INF/classes/spring   
classpath:spring/applicationContext-*.xml

applicationContext-service.xml :如果它已经在 jar 文件中,则不需要复制它


示例 main-config.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee 
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd         
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">


<import resource="classpath:spring/config1.xml" />
<import resource="classpath:spring/config2.xml" />
.
.
<import resource="classpath:spring/configN.xml" />


</beans>

You need to place your config files into the classpath.

WEB-INF/classess  is the directory you need to place your configuration files
classpath:applicationContext-*.xml will then work

or sth similar to this to keep them in one place

WEB-INF/classes/spring   
classpath:spring/applicationContext-*.xml

applicationContext-service.xml : You dont need to copy this one if it is already in the jar file


Sample main-config.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/aop 
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee 
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd         
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">


<import resource="classpath:spring/config1.xml" />
<import resource="classpath:spring/config2.xml" />
.
.
<import resource="classpath:spring/configN.xml" />


</beans>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文