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

  • 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
    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.

    Comment


    • #3
      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.

      Comment

      Working...
      X