无法找到 activemq.xml 的 Spring NamespaceHandler



>我正在尝试在Spring Boot 2.1.7应用程序中配置ActiveMQ代理,特别是启用statisticsBrokerPlugin。

My 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 的帖子。

有什么想法吗?

Spring在 XML 中添加非 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 对此有更多介绍。

最新更新