Announcement Announcement Module
No announcement yet.
QueueChannel ClassCastException Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • QueueChannel ClassCastException


    I have queue channel defined as:

    channel id="myChannel">
    	<queue capacity="100"/>		
    In some code I retrieve the channel via the application context as:

    QueueChannel myChannel = (QueueChannel ) ctx.getBean("myChannel");
    I don't use the PollableChannel interface because I need to call the clear() method on the queue.

    All was good until I tried to add JMX support as:

    <jmx:mbean-export default-domain="com.mypackage" server="mbeanServer"/>
    <beans:bean id="mbeanServer" class="">
    	<beans:property name="locateExistingServerIfPossible" value="true"/>
    Since then I get a ClassCastException:

    java.lang.ClassCastException: $Proxy224 cannot be cast to el

    If I use the interface (PollableChannel) I avoid the error but I can't execute clear() method.

    żIs there any way to workaround this get my channel as a QueueChannel?

    Thanks in advance.

  • #2

    Thanks for your question! The issue you encounter has to do with the fact that the Spring Integration JMX support adds JDK dynamic proxies (AOP) to the Spring Integration beans. These however only work with interfaces, hence the exception you encounter using a concrete class implementation. For more information please see:

    Unfortunately, the underlying Spring Integration JMX classes ONLY support JDK dynamic proxies. Therefore, it is not possible to use CGLib based proxies (as you can usually do using Spring AOP) when exposing Spring Integration beans via JMX.

    Nevertheless, this is unfortunately not documented in the Spring Integration reference manual itself. I have created a Jira to add an additional paragraph to the Spring Integration reference manual describing in more detail the proxying behavior when exposing Spring Integration beans through JMX:

    Typically, users should probably not be relying on concrete classes anyway. However, I see you desire to expose the clear() operation. It should be on an interface, though. If you like to see this added, please create a Jira for this and add the link to that Jira back to this forum thread.