【问题标题】:Starting ActiveMQ message listener in Tomcat?在 Tomcat 中启动 ActiveMQ 消息侦听器?
【发布时间】:2011-01-13 15:50:49
【问题描述】:

我创建了一个 ActiveMQ MessageListener 并使用 Spring 对其进行了配置。我在 Tomcat 中托管监听器。当我启动 Web 应用程序(仅具有侦听器)时,侦听器是否应该自动启动?还是我需要额外的配置?

这就是我所拥有的。首先,更新 web.xml 以允许 spring 在启动时自行配置,

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/classes/spring/applicationContext.xml</param-value>
    </context-param>

</web-app>

然后我创建了 applicationContext.xml 来配置 ActiveMQ 监听器,

<?xml version="1.0" encoding="UTF-8"?>
<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:amq="http://activemq.apache.org/schema/core"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:annotation-config />
    <context:component-scan base-package="com.somepackage"/>

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

    <bean id="jmsFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="tcp://localhost:61616" />
    </bean>

    <bean id="documentListener" class="com.somepackage.SomeListener" />

    <bean id="container"
        class="org.springframework.jms.listener.DefaultMessageListenerContainer">
        <property name="connectionFactory" ref="cachingConnectionFactory"/>
        <property name="messageListener" ref="documentListener"/>
        <property name="destinationName" value="STOCKS.MSFT" />
    </bean>

    <bean id="cachingConnectionFactory"
        class="org.springframework.jms.connection.CachingConnectionFactory">
        <property name="targetConnectionFactory" ref="jmsFactory" />
        <property name="sessionCacheSize" value="1" />
    </bean>
</beans>

就是这样。根据我在网上看到的情况,我不知道这是否就是我所需要的?也许我需要在 Tomcat 中进行一些其他配置来启动监听器?

【问题讨论】:

    标签: tomcat6 listener activemq


    【解决方案1】:

    这确实有效。我正在使用 Eclipse 进行调试,我必须在它突然决定工作之前进行几次刷新、清理和重新启动。

    要回答我自己的问题,是的,这就是从 Tomcat 中在 Web 应用程序中运行侦听器所需的全部内容。它可以完全只用 XML 配置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-04
      相关资源
      最近更新 更多