Results 1 to 3 of 3

Thread: TypeMismatchException on NameMatchMethodPointcutAdvisor

  1. #1
    Join Date
    Nov 2006
    Posts
    29

    Angry TypeMismatchException on NameMatchMethodPointcutAdvisor

    Hello,

    I surfed the entire forum. Still I couldn't fix my problem. I hope I will get an answer from experts.

    I have NameMatchMethodPointcutAdvisor on mappedName 'onMessage'.
    My Advice is ignored for some reasons. I am proxying against javax.jms.MessageListener which is an interface.

    My problem is
    ===========
    a) If I use <property name="targetSource" ref="myMessageListener"/>, I am getting
    org.springframework.beans.TypeMismatchException: Failed to convert property valu
    e of type [com.abc.MessageConsumer] to required ty
    pe [org.springframework.aop.TargetSource] for property 'targetSource'; nested ex
    ception is java.lang.IllegalArgumentException: No matching editors or conversion
    strategy found

    b) If I use <property name="target" ref="myMessageListener"/>, The advice is ignored and onMessage method is called. I tried with targetName instead of target. Still it is ignored.


    My code
    =======
    1) applicationContext.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

    <beans>

    <bean id="messageProcessorAdvisor" abstract="true" class="org.springframework.aop.support.NameMatchMe thodPointcutAdvisor">
    <property name="mappedName" value="onMessage"/>
    </bean>

    <bean id="messageAdvisor" parent="messageProcessorAdvisor">
    <property name="advice">
    <bean class="com.abc.spring.advice.MessageAdvice"/>
    </property>
    </bean>

    <bean id="myMessageListener" class="com.abc.MessageConsumer">
    </bean>

    <bean id="proxyProcessor" class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="proxyInterfaces" value="javax.jms.MessageListener"/>
    <!-- use non-pooled definition -->
    <property name="target" ref="myMessageListener"/>
    <property name="interceptorNames">
    <list>
    <idref local="messageAdvisor"/>
    </list>
    </property>
    </bean>

    <bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName" value="jms/abc" />
    <property name="resourceRef" value="true" />
    </bean>

    <bean id="jmsDestination" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName" value="jms/xyz" />
    <property name="resourceRef" value="true" />
    </bean>

    <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMes sageListenerContainer102">
    <property name="concurrentConsumers" value="5"/>
    <property name="connectionFactory" ref="jmsQueueConnectionFactory" />
    <property name="destination" ref="jmsDestination" />
    <property name="sessionTransacted" value="true" />
    <property name="messageListener" ref="myMessageListener" />
    </bean>

    </beans>

    2) MessageConsumer implements javax.jms.MessageListener

    public void onMessage(Message message) {
    .......
    }

    3) MessageAdvice implements MethodInterceptor

    public Object invoke(MethodInvocation invocation) throws Throwable {
    .........
    }

    Can somebody tell me why the advice is not invoked?

    Thank you.
    Venkata Kanugula.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    You are creating a proxy but aren't doing anything with the proxy. Change your proxy config to the following and remove the myMessageListener bean you have now.

    Code:
    <bean id="myMessageListener" class="org.springframework.aop.framework.ProxyFactoryBean">
        <property name="proxyInterfaces" value="javax.jms.MessageListener"/>
        <property name="target">
            <bean class="com.abc.MessageConsumer"/>
        </property>
        <property name="interceptorNames">
            <list>
                <idref local="messageAdvisor"/>
            </list>
        </property>
    </bean>
    I created your messageConsumer as an inner bean which prevents access to the non proxied object. No use the proxy in your listenerContainer config, although it should be picked up automatically because I changd the name of the proxy.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Nov 2006
    Posts
    29

    Default Thank you. It is working now!

    Hello Marten,

    Thank you very much. I modified it as below (I am posting my configuration so it will help others). It is perfectly working now!

    I thought Spring will automatically invoke any declared Proxy.

    applicationContext.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

    <beans>

    <bean id="messageProcessorAdvisor" abstract="true" class="org.springframework.aop.support.NameMatchMe thodPointcutAdvisor">
    <property name="mappedName" value="onMessage"/>
    </bean>

    <bean id="messageAdvisor" parent="messageProcessorAdvisor">
    <property name="advice">
    <bean class="com.abc.spring.advice.MessageAdvice"/>
    </property>
    </bean>

    <bean id="myMessageListener" class="org.springframework.aop.framework.ProxyFact oryBean">
    <property name="proxyInterfaces" value="javax.jms.MessageListener"/>
    <!-- use non-pooled definition -->
    <property name="target">
    <bean class="com.abc.MessageConsumer"/>
    </property>

    <property name="interceptorNames">
    <list>
    <idref local="messageAdvisor"/>
    </list>
    </property>
    </bean>

    <bean id="jmsQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName" value="jms/abc" />
    <property name="resourceRef" value="true" />
    </bean>

    <bean id="jmsDestination" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName" value="jms/xyz" />
    <property name="resourceRef" value="true" />
    </bean>

    <bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMes sageListenerContainer102">
    <property name="concurrentConsumers" value="5"/>
    <property name="connectionFactory" ref="jmsQueueConnectionFactory" />
    <property name="destination" ref="jmsDestination" />
    <property name="sessionTransacted" value="true" />
    <property name="messageListener" ref="myMessageListener" />
    </bean>

    </beans>


    Thank you.
    Venkata Kanugula.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •