I am facing the famous BeanNotOfRequiredTypeException
exception while configuring ActiveMQ (5.14.0) on Tomcat 8 (8.5.4) to expose a JMS queue for a Spring (3.2.8) application.
Fixes suggested by several similar questions (to change AOP and proxy behvior) did not help: after applying the changes, the same error came up again:
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]
even if ActiveMQQueue
is effectively of type Queue
.
Current configuration:
The Spring application looks the queue up via JNDI:
<jee:jndi-lookup jndi-name="jms/someQueue" id="someQueue" />
The queue is referenced in the web.xml
file:
<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>
On server side, the queue is configured in the Tomcat server.xml
file as a GlobalNamingResources
as:
<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"
/>
That's the minimal configuration applied so far. The same approach has been applied for a data source and a mail service (server.xml
+ web.xml
+ JNDI) working fine, however failing on queue configuration.
Question(s): why Spring keeps on seeing it as a wrong type? Is any further configuration required to set-up ActiveMQ on Tomcat 8 and expose a queue via JNDI?