未找到 Spring 配置

标签 spring configuration applicationcontext

我的 web.xml 中有以下内容:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext-*.xml</param-value>
</context-param>

我有 2 个文件:

  • web.xml 旁边的 WEB-INF 中的 applicationContext-web.xml
  • myapp-service.jar 中的 applicationContext-service.xml

部署应用程序时,我得到一个

No matching bean of type [AServiceBean] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.

似乎找不到 applicationContext-service.xml。如果我将其复制到 web.xml 旁边,它就可以正常工作。我不明白为什么会发生这种情况。

服务器是 Tomcat 6。

感谢任何帮助。 谢谢。

编辑

澄清一下:如果我使用

<param-value>
    classpath:applicationContext-web.xml,
    classpath:applicationContext-service.xml
</param-value>

应用程序部署没有任何问题,因此只需找到(或找不到)applicationContext-service.xml

最佳答案

尝试使用classpath*:applicationContext-*.xml(冒号前有星号)。

但是它可能不起作用,例如JBoss 有问题,要使其工作,您需要使用 jboss 的一些特殊类加载器。

此外,还有一些problems using patterns在根中。

无论如何,我建议避免使用模式,最好使用两个显式的 import 语句创建一个 applicationContext.xml

关于未找到 Spring 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8401763/

相关文章:

java - 在 Spring Security 中添加新用户

spring - 如何禁用Spring boot默认错误处理?

java - 使用 Spring 3.1 的属性抽象动态访问属性

android - 具有多个配置 Activity 的一个小部件 (Android)

java - 如何防止 Gradle 将资源文件包含在 JAR 中

java - 如何在spring mvc中删除session属性

java - 重新读取配置而不重启

c# - 无法从 .NET Core 2 控制台应用程序中的 config.json 读取数据

java - 无法加载 ApplicationContext : IllegalArgumentException

java - Autowiring 到列表中时的 Bean 顺序