0

我正在尝试创建一个示例 JMS 应用程序。我想要它做的就是启动,并让生产者在数据发送到端点时向消费者发送消息。

我的 spring 配置有问题,我不知道我需要在 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)
4

1 回答 1

2

至少 pom.xml 中的某些依赖项完全是错误的。查看底部的hornetq-logginghornetq-transportshornetq-jms。这些在 2.3.X 版本中不再存在,应该删除。

通常,如果您有任何来自 HornetQ 主项目的 JAR,它应该使用相同的版本。使用 . 删除所有这些罐子2.0.0.GA。其中一些已重命名,在任何一种情况下,您都应该尝试只让org.hornetqJAR 使用相同的版本。在你的 pom 的情况下,那将是2.3.0-Final. 顺便说一句,最新版本是2.3.2-Final,你应该升级到那个恕我直言。

IIRChornetq-jms被破解为hornetq-jms-serveror hornetq-jms-client。你可能想要hornetq-jms-client. 核心也被分解成hornetq-core-clientand hornetq-server

2.3.2.Final在此处搜索带有版本号的 JAR https://repository.jboss.org/nexus/index.html#nexus-search;quick~org.hornetq(做一些更高级的搜索)。

于 2013-07-19T11:21:42.350 回答