Reputation: 3264
I'm trying to configure an ActiveMQ broker in a Spring Boot 2.1.7 application, specifically to enabled the 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>
integrated using
@ImportResource("classpath:activemq.xml")
in a Kotlin / Gradle application with build.gradle.kts
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")
}
Starting the application fails with
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]
I'm finding a few posts regarding an issue with a Maven plugin, but nothing with Gradle.
Any ideas?
Upvotes: 1
Views: 427
Reputation: 3264
Spring requires definition of META-INF/spring.handlers when adding non-Spring configuration in XML (as described here: https://docs.spring.io/spring/docs/3.0.x/spring-framework-reference/html/extensible-xml.html). The META-INF/spring.handlers definition for ActiveMQ is defined in
implementation("org.apache.activemq:activemq-spring")
and this dependency is NOT added by the Spring Boot "spring-boot-starter-activemq". So adding above line in build.gradle.kts resolved the issue.
Beware that there are further issues when building a shadow JAR (=fat JAR Gradle-style), as the various META-INF/spring.** files need be merged. https://dzone.com/articles/gradle-spring-woes-issues-in-creating-single-jar-b has more on this.
Upvotes: 1