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

  • QueueChannel ClassCastException

    Hi,

    I have queue channel defined as:

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

    Code:
    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:

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

    java.lang.ClassCastException: $Proxy224 cannot be cast to org.springframework.integration.channel.QueueChann 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
    Hi,

    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:

    http://static.springsource.org/sprin...uction-proxies

    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:

    https://jira.springsource.org/browse/INT-2113

    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.

    Cheers,

    Gunnar

    Comment

    Working...
    X