【问题标题】:activemq endpoint in spring boot ClassNotFoundExceptionspring boot ClassNotFoundException中的activemq端点
【发布时间】:2020-06-23 06:11:43
【问题描述】:

我正在尝试转向 Spring Boot,以便在使用 Camel 和 ActiveMQ 的应用程序中获得更清晰的依赖关系。我曾经在 XML 文件中配置了 activemq 端点:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jms="http://www.springframework.org/schema/jms"
    xmlns:amq="http://activemq.apache.org/schema/core"
    xsi:schemaLocation="http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core-5.5.0.xsd
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms-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/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<context:property-placeholder location="classpath:config.properties"/>

<bean id="jmsConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="${gatewaybroker}"/>
</bean>

<bean id="pooledJmsConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start"  destroy-method="stop">
    <property name="maxConnections" value="8" />
    <property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>

<bean id="jmsConfig"
   class="org.apache.camel.component.jms.JmsConfiguration">
   <property name="connectionFactory" ref="pooledJmsConnectionFactory"/>
   <property name="concurrentConsumers" value="10"/>
</bean>

<!-- create a Camel ActiveMQ component -->
<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="configuration" ref="jmsConfig"/>

    <!-- if we are using transacted then enable CACHE_CONSUMER (if not using XA) to run faster
         see more details at: http://camel.apache.org/jms
    <property name="transacted" value="true"/>
    <property name="cacheLevelName" value="CACHE_CONSUMER" />
    -->   
</bean>   
</beans>

然后使用该 ActiveMQ 端点调用路由:

from("activemq:queue:configuratelearningmodule")
    .routeId(routeid)
    .autoStartup(false)
    .process(       
        new Processor(){                    
            public void process(Exchange exchange) throws Exception {
//                         etc....                          

现在我创建了一个 spring-boot 应用程序并尝试逐步迁移。我没有找到使用自动配置的 spring-boot activemq 访问端点“activemq”的方法,所以我试图保留我的 xml 配置文件。毕竟,我可以自己配置 activemq 端点,我只使用 spring-boot 来不关心所有元素之间的版本冲突(jpa/hibernate、spring、camel、activemq、mqtt 等......)

但是我收到了这条消息:

An exception occured while executing the Java class. 
Error creating bean with name 'dataSourceInitializerPostProcessor':
Unsatisfied dependency expressed through field 'beanFactory'; 
nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: 
Error loading class [org.apache.activemq.camel.component.ActiveMQComponent] 
for bean with name 'activemq' defined in class path resource [jmsconfig.xml]: 
problem with class file or dependent class; 
nested exception is java.lang.NoClassDefFoundError: org/apache/camel/impl/HeaderFilterStrategyComponent

在 Camel 3.1 迁移页面上,他们告诉 activemq-camel 已移至 camel,因此我正在使用 camel-activemq 组件调整我的 pom.xml,但这并没有改变任何东西。

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-spring-boot-starter</artifactId>
  <version>3.1.0</version>
</dependency>

<dependency>
  <groupId>org.apache.activemq</groupId>
  <artifactId>activemq-camel</artifactId>
</dependency>

<dependency>
  <groupId>org.apache.activemq</groupId>
  <artifactId>activemq-pool</artifactId>
</dependency>       

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-activemq</artifactId>
  <version>3.1.0</version>
</dependency>        

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-core</artifactId>
  <version>3.1.0</version>
</dependency>

知道如何让 activemq 端点在 spring-boot 中工作吗?

【问题讨论】:

标签: spring-boot apache-camel activemq


【解决方案1】:

你可以试试

<dependency>
        <groupId>org.apache.activemq</groupId>
        <artifactId>activemq-all</artifactId>
        <version>5.15.2</version>
</dependency>

问候

【讨论】:

  • 添加activemq依赖,java.lang.NoSuchMethodError: 'void org.springframework.util.Assert.notNull(java.lang.Object, java.util.function.Supplier)' at org.springframework.format.support.FormattingConversionService.getFieldType (FormattingConversionService.java:123)
  • 试一试start.spring.io,您可以在其中定义项目所需的内容,生成它,然后添加缺少的依赖项和代码部分
猜你喜欢
  • 1970-01-01
  • 2017-08-01
  • 2021-03-10
  • 2018-08-15
  • 1970-01-01
  • 1970-01-01
  • 2017-07-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多