【问题标题】:Unable to locate Spring NamespaceHandler for activemq.xml找不到 activemq.xml 的 Spring NamespaceHandler
【发布时间】:2020-01-02 13:59:51
【问题描述】:

我正在尝试在 Spring Boot 2.1.7 应用程序中配置 ActiveMQ 代理,专门用于启用 statisticsBrokerPlugin。

我的activemq.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:amq="http://activemq.apache.org/schema/core"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://activemq.apache.org/schema/core
        http://activemq.apache.org/schema/core/activemq-core.xsd">

    <amq:broker brokerName="broker1" persistent="false">
        <amq:plugins>
            <amq:statisticsBrokerPlugin/>
        </amq:plugins>
        <amq:transportConnectors>
            <amq:transportConnector name="vm" uri="vm://embedded?broker.persistent=false,useShutdownHook=false"/>
        </amq:transportConnectors>
    </amq:broker>

    <amq:connectionFactory id="jmsFactory" brokerURL="vm://embedded"/>
</beans>

集成使用

@ImportResource("classpath:activemq.xml")

在带有 build.gradle.kts 的 Kotlin / Gradle 应用程序中

repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-activemq")
    implementation("org.springframework.boot:spring-boot-starter-security")
    implementation("org.springframework.boot:spring-boot-starter-integration")
    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-configuration-processor")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    testImplementation("org.springframework.boot:spring-boot-starter-test")    {
        exclude(module = "junit")
    }
    testImplementation("org.springframework.security:spring-security-test")
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.3.1")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.3.1")
}

启动应用程序失败

Caused by: 
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: 
Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://activemq.apache.org/schema/core]
Offending resource: class path resource [activemq.xml]

我发现了一些关于 Maven 插件问题的帖子,但没有关于 Gradle 的问题。

有什么想法吗?

【问题讨论】:

    标签: java spring-boot gradle activemq spring-jms


    【解决方案1】:

    在 XML 中添加非 Spring 配置时,Spring 需要定义 META-INF/spring.handlers(如下所述:https://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/extensible-xml.html)。 ActiveMQ 的 META-INF/spring.handlers 定义在

    implementation("org.apache.activemq:activemq-spring")
    

    Spring Boot "spring-boot-starter-activemq" 不会添加此依赖项。所以在 build.gradle.kts 中添加上面的行解决了这个问题。

    请注意,在构建影子 JAR(=fat JAR Gradle 样式)时还会出现更多问题,因为需要合并各种 META-INF/spring.** 文件。 https://dzone.com/articles/gradle-spring-woes-issues-in-creating-single-jar-b 对此有更多了解。

    【讨论】:

      猜你喜欢
      • 2015-12-01
      • 1970-01-01
      • 2015-12-23
      • 2015-11-17
      • 1970-01-01
      • 2013-02-13
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多