我正面临 famous BeanNotOfRequiredTypeException
在 Tomcat 8 (8.5.4) 上配置 ActiveMQ (5.14.0) 为 Spring (>3.2.8) 申请。
several 建议的修复类似的问题(更改 AOP 和代理行为)没有帮助:应用更改后,同样的错误再次出现:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'notificationService': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'someQueue' must be of type [javax.jms.Queue], but was actually of type [org.apache.activemq.command.ActiveMQQueue]
即使ActiveMQQueue
实际上是 Queue
类型.
当前配置:
Spring 应用程序通过 JNDI 查找队列:
<jee:jndi-lookup jndi-name="jms/someQueue" id="someQueue" />
队列在 web.xml
文件中被引用:
<resource-ref>
<description>Factory</description>
<res-ref-name>jms/someConnectionFactory</res-ref-name>
<res-type>javax.jms.QueueConnectionFactory</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>Queue</description>
<res-ref-name>jms/someProcessQueue</res-ref-name>
<res-type>javax.jms.Queue</res-type>
<res-auth>Container</res-auth>
</resource-ref>
在服务器端,队列在 Tomcat server.xml
文件中配置为 GlobalNamingResources
如下:
<Resource name="jms/someConnectionFactory"
auth="Container"
type="org.apache.activemq.ActiveMQConnectionFactory"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
description="JMS Connection Factory"
brokerURL="vm://localhost"
brokerName="LocalActiveMQBroker"
useEmbeddedBroker="true"
/>
<Resource name="jms/someQueue"
auth="Container"
type="org.apache.activemq.command.ActiveMQQueue"
description="JMS queue"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
physicalName="SOME.QUEUE"
/>
这是目前应用的最小配置。相同的方法已应用于数据源和邮件服务(server.xml
+ web.xml
+ JNDI)工作正常,但队列配置失败。
问题:为什么 Spring 一直将其视为错误类型?在 Tomcat 8 上设置 ActiveMQ 并通过 JNDI 公开队列是否需要任何进一步的配置?
最佳答案
这不是您在服务器端和客户端声明两种不同类型的事实吗?
//On the Tomcat side
type="org.apache.activemq.command.ActiveMQQueue"
//In the web.xml of your app
<res-type>javax.jms.Queue</res-type>
为了更好地解释:你在这里感到沮丧:你在你的应用程序 web.xml 中声明了一个队列接口(interface)类型,你收到了一些实现它的东西 -> downcasting
应该相反或者服务器类型设置为queue
关于java - Tomcat8 和 ActiveMQ : Bean named 'someQueue' must be of type [javax. jms.Queue],但实际上是 [org.apache.activemq.command.ActiveMQQueue] 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39127246/