我正在尝试创建一个示例JMS应用程序。我想要它做的就是启动,并让生产者在将数据发送到端点时向消费者发送消息。
我的弹簧配置有问题,而且我不知道我需要使用Maven引入哪些依赖项(以及哪些版本)。我从一个简单的Roo项目开始。
首先,我的spring xml看起来不错,其次,我的maven依赖是对吗?从我得到的错误中,我认为我已经从Maven中获得了过时的依赖。我还在我的jboss配置中添加了一个访客用户/角色。
以下是我的spring xml的相关部分:
<bean id="jnditemplate" class="org.springframework.jndi.JndiTemplate">
<property name="environment">
<props>
<prop key="java.naming.factory.initial">org.jboss.naming.remote.client.InitialContextFactory</prop>
<prop key="java.naming.provider.url">remote://127.0.0.1:4447</prop>
<prop key="java.naming.security.principal">guest</prop>
<prop key="java.naming.security.credentials">password1</prop>
</props>
</property>
</bean>
<bean id="connectionfactory" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jnditemplate"/>
<property name="jndiName" value="jms/RemoteConnectionFactory"/>
</bean>
<bean id="destination" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiTemplate" ref="jnditemplate"/>
<property name="jndiName" value="jms/queue/test"/>
</bean>
<bean id="credentialsconnectionfactory"
class="org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter">
<property name="targetConnectionFactory" ref="connectionfactory"/>
<property name="username" value="guest"/>
<property name="password" value="password1"/>
</bean>
<bean id="jmstemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="credentialsconnectionfactory"/>
<property name="defaultDestination" ref="destination"/>
</bean>
<bean class="org.springframework.jms.listener.SimpleMessageListenerContainer">
<property name="connectionFactory" ref="credentialsconnectionfactory"/>
<property name="destination" ref="destination"/>
<property name="messageListener" ref="receiver"/>
</bean>
<bean id="sender" class="com.example.web.Producer">
<property name="jmsTemplate" ref="jmstemplate"/>
</bean>
<bean id="receiver" class="com.example.web.Consumer"/>
以下是我的POM的相关部分:
<spring.version>3.2.0.RELEASE</spring.version>
<hornetq.client.version>2.3.0.Final</hornetq.client.version>
...
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<version>7.1.1.Final</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-core-client</artifactId>
<version>${hornetq.client.version}</version>
</dependency>
<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-jms-client</artifactId>
<version>${hornetq.client.version}</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-ejb-client</artifactId>
<version>1.0.5.Final</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.ejb3</groupId>
<artifactId>jboss-ejb3-ext-api</artifactId>
<version>2.0.0-beta-2</version>
</dependency>
<dependency>
<groupId>org.jboss.netty</groupId>
<artifactId>netty</artifactId>
<version>3.2.9.Final</version>
</dependency>
<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-core</artifactId>
<version>2.0.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-jms</artifactId>
<version>2.0.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-logging</artifactId>
<version>2.0.0.GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hornetq</groupId>
<artifactId>hornetq-transports</artifactId>
<version>2.0.0.GA</version>
<scope>compile</scope>
</dependency>
我的jboss standalone.xml的相关部分:
<subsystem xmlns="urn:jboss:domain:messaging:1.1">
<hornetq-server>
<persistence-enabled>true</persistence-enabled>
<journal-file-size>10240</journal-file-size>
<journal-min-files>2</journal-min-files>
<connectors>
<netty-connector name="netty" socket-binding="messaging"/>
<netty-connector name="netty-throughput" socket-binding="messaging-throughput">
<param key="batch-delay" value="50"/>
</netty-connector>
<in-vm-connector name="in-vm" server-id="0"/>
</connectors>
<acceptors>
<netty-acceptor name="netty" socket-binding="messaging"/>
<netty-acceptor name="netty-throughput" socket-binding="messaging-throughput">
<param key="batch-delay" value="50"/>
<param key="direct-deliver" value="false"/>
</netty-acceptor>
<in-vm-acceptor name="in-vm" server-id="0"/>
</acceptors>
<security-settings>
<security-setting match="#">
<permission type="send" roles="guest"/>
<permission type="consume" roles="guest"/>
<permission type="createNonDurableQueue" roles="guest"/>
<permission type="deleteNonDurableQueue" roles="guest"/>
</security-setting>
</security-settings>
<address-settings>
<address-setting match="#">
<dead-letter-address>jms.queue.DLQ</dead-letter-address>
<expiry-address>jms.queue.ExpiryQueue</expiry-address>
<redelivery-delay>0</redelivery-delay>
<max-size-bytes>10485760</max-size-bytes>
<address-full-policy>BLOCK</address-full-policy>
<message-counter-history-day-limit>10</message-counter-history-day-limit>
</address-setting>
</address-settings>
<jms-connection-factories>
<connection-factory name="InVmConnectionFactory">
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/ConnectionFactory"/>
</entries>
</connection-factory>
<connection-factory name="RemoteConnectionFactory">
<connectors>
<connector-ref connector-name="netty"/>
</connectors>
<entries>
<entry name="RemoteConnectionFactory"/>
<entry name="java:jboss/exported/jms/RemoteConnectionFactory"/>
</entries>
</connection-factory>
<pooled-connection-factory name="hornetq-ra">
<transaction mode="xa"/>
<connectors>
<connector-ref connector-name="in-vm"/>
</connectors>
<entries>
<entry name="java:/JmsXA"/>
</entries>
</pooled-connection-factory>
</jms-connection-factories>
<jms-destinations>
<jms-queue name="testQueue">
<entry name="queue/test"/>
<entry name="java:/queue/test"/>
<entry name="java:jboss/exported/jms/queue/test"/>
</jms-queue>
<jms-queue name="DemoQueue">
<entry name="/queue/DemoQueue"/>
</jms-queue>
<jms-topic name="testTopic">
<entry name="topic/test"/>
<entry name="java:jboss/exported/jms/topic/test"/>
</jms-topic>
</jms-destinations>
</hornetq-server>
</subsystem>
<subsystem xmlns="urn:jboss:domain:weld:1.0"/>
</profile>
以及我尝试通过eclipse / vmware vFabric启动时收到的错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.jms.listener.SimpleMessageListenerContainer#0' defined in ServletContext resource [/WEB-INF/spring/webmvc-config.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hornetq.utils.HornetQThreadFactory.<init>(Ljava/lang/String;Z)V
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1486)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:524)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
答案 0 :(得分:2)
pom.xml中至少有一些依赖项是错误的。请查看hornetq-logging
,hornetq-transports
,hornetq-jms
等的底部。这些版本在2.3.X版本中不再存在,应该删除。
通常,如果你有HornetQ主项目中的任何JAR,它应该使用相同的版本。使用2.0.0.GA
删除所有这些jar。其中一些已重命名,在任何一种情况下,您都应该尝试使用相同版本的org.hornetq
JAR。如果你的pom是2.3.0-Final
。顺便说一句,最新版本是2.3.2-Final
,你应该升级到那个恕我直言。
IIRC hornetq-jms
分为hornetq-jms-server
或hornetq-jms-client
。你可能想要hornetq-jms-client
。核心也分为hornetq-core-client
和hornetq-server
。
在此处https://repository.jboss.org/nexus/index.html#nexus-search;quick~org.hornetq搜索版本号为2.3.2.Final
的JAR(进行更高级的搜索)。