gpt4 book ai didi

java - 如何在没有 XML 的情况下将 Camel 与 Spring 一起使用

转载 作者:行者123 更新时间:2023-11-30 02:12:56 25 4
gpt4 key购买 nike

我正在阅读《Camel in Action》第二版,它指导使用 Spring-Camel XML 命名空间配置将 Camel 嵌入到 Spring 中,自动发现定义为 Spring beans 的组件等。这是一个示例。

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

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<package>org.apache.camel.example.spring</package>
</camelContext>

<!-- lets configure the default ActiveMQ broker URL -->
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="vm://localhost?broker.persistent=false&amp;broker.useJmx=true"/>
</bean>
</property>
</bean>

</beans>

如何在不使用 XML 配置而是使用 Spring Java 配置的情况下实现此目的?

最佳答案

引用this documentation来自 Camel 。并引用this用于 Activemq 配置。

此处仅添加一个片段:

public class MyRouteConfiguration extends CamelConfiguration {

@Autowire
private MyRouteBuilder myRouteBuilder;

@Autowire
private MyAnotherRouteBuilder myAnotherRouteBuilder;

@Override
public List<RouteBuilder> routes() {
return Arrays.asList(myRouteBuilder, myAnotherRouteBuilder);
}
}

关于java - 如何在没有 XML 的情况下将 Camel 与 Spring 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49586181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com