我正在开发一个项目,我们决定使用 jms 和 hornetq 作为提供程序添加一些交互。
我对 Camel 很陌生,所以我遇到了一些问题(如果你可能认为是微不足道的)。
目标是初始化连接工厂并添加 jms 组件。但是,据我了解,它不能直接在路由配置器中完成。所以我创建了camel-config.xml并将其放置到resources/目录中。
我是这样填写的:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
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">
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">org.jnp.interfaces.NamingContextFactory</prop>
<prop key="java.naming.provider.url">jnp://localhost:1099</prop>
<prop key="java.naming.factory.url.pkgs">org.jnp.interfaces:org.jboss.naming</prop>
</props>
</property>
</bean>
<bean id="jmsQueueConnectionFactory"
class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate">
<ref bean="jndiTemplate"/>
</property>
<property name="jndiName">
<value>ConnectionFactory</value>
</property>
</bean>
<bean name="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsQueueConnectionFactory"/>
</bean>
</beans>
该项目不使用 Spring,因此它是我发现的唯一不使用 Spring 的 xml 示例。
在路由配置器中,我使用 routeBuilder.from("jms:queue:top").to("...");
但是,当我启动项目时,它会抛出 FailedToCreateEndpointException 并声明
“未找到具有架构的组件:jms”。
我想 xml 文件根本没有被使用,但我只是不明白如何指向它。
期待听到任何建议。
最佳答案
<beans/>
XML 是一个 Spring 配置,必须以某种方式引导。您可以查看 Tomcat ActiveMQ 示例,发现 here ,展示了如何在 servlet 环境中执行此操作。特别看一下web.xml
:
<!-- location of spring XML files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:broker.xml,
classpath:camel-config.xml
</param-value>
</context-param>
<!-- the listener that kick-starts Spring, which loads the XML files and start our application -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
当然,您也可以使用仅 Java 设置,如下所示:
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
ModelCamelContext context = new DefaultCamelContext();
context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
关于java - 未找到架构 : jms 的组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26073244/