我正在开发一个Spring Web服务,我需要处理一些异步过程。我发现JMS
ActiveMQ
是实现这一目标的好方法。我已经下载并安装ActiveMQ
创建了两个队列testQueue1
和testQueue2
,在spring-ws-servlet.xml
文件中添加了以下bean。
<bean id="activeMQConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
</bean>
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<constructor-arg ref="activeMQConnectionFactory" />
</bean>
<bean id="sampleQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg index="0" value="testQueue1"/>
</bean>
<bean id="sampleJmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
<property name="defaultDestination" ref="sampleQueue" />
</bean>
<bean id="messageSender" class="com.test.async.AsyncMessageSender">
<constructor-arg index="0" ref="sampleJmsTemplate" />
</bean>
<bean id="messageReceiver" class="com.test.async.AsyncMessageReceiver">
</bean>
<bean class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destinationName" value="testQueue2" />
<property name="messageListener" ref="messageReceiver" />
</bean>
以下是我的两个班级。
public class AsyncMessageSender {
private final JmsTemplate jmsTemplate;
public AsyncMessageSender(final JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}
public void send(final Map map) {
jmsTemplate.convertAndSend(map);
}
}
并在pom.xml
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.9.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jms</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
现在,当我尝试在eclipse中使用SoapUI插件测试我的Web服务时,我收到以下错误。
Mar 20, 2014 12:57:41 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet spring-ws
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'messageReceiver' must be of type [org.springframework.ws.transport.WebServiceMessageReceiver], but was actually of type [com.test.async.AsyncMessageReceiver]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:376)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:979)
at org.springframework.ws.transport.http.MessageDispatcherServlet.initMessageReceiver(MessageDispatcherServlet.java:448)
at org.springframework.ws.transport.http.MessageDispatcherServlet.initStrategies(MessageDispatcherServlet.java:371)
at org.springframework.ws.transport.http.MessageDispatcherServlet.onRefresh(MessageDispatcherServlet.java:300)
at org.springframework.web.servlet.FrameworkServlet.onApplicationEvent(FrameworkServlet.java:772)
at org.springframework.web.servlet.FrameworkServlet$ContextRefreshListener.onApplicationEvent(FrameworkServlet.java:1083)
at org.springframework.web.servlet.FrameworkServlet$ContextRefreshListener.onApplicationEvent(FrameworkServlet.java:1080)
at org.springframework.context.event.GenericApplicationListenerAdapter.onApplicationEvent(GenericApplicationListenerAdapter.java:52)
at org.springframework.context.event.SourceFilteringListener.onApplicationEventInternal(SourceFilteringListener.java:100)
at org.springframework.context.event.SourceFilteringListener.onApplicationEvent(SourceFilteringListener.java:69)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:98)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:333)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:776)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:485)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651
任何解决此问题的想法都将受到高度赞赏。