Announcement Announcement Module
Collapse
No announcement yet.
Problem with proxied methods Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with proxied methods

    Hi Community'guys:

    I have the following case:
    Code:
    class A implements IA {
      void saveTxC(C c) {
    	B b = getTxCurrentB();
            c.setB(b);
            dao.save(c);
      }
    
      B getTxCurrentB() {
          B b = dao.getCurremtB();
          return b;
      }
    }
    Code:
        <bean 
            id="txService" 
            class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" 
            abstract="true"
            lazy-init="true">
            <property name="transactionManager">
                <ref bean="txManager"/>
            </property>
            <property name="transactionAttributes">
                <props>
                    <prop key="getTx*">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="saveTx*">PROPAGATION_REQUIRED</prop>
                </props>
            </property>
            <property name="preInterceptors">
                <list>
                    <ref bean="preFilterDomainsByClienteWeb" />
                	<ref bean="setterClienteWebAndUserInMethod"/>
                    <ref bean="securityInterceptor"/>
                </list>
            </property>
            <property name="postInterceptors">
                <list>
                    <ref bean="postFilterDomainsByClienteWeb" />
                </list>
            </property>
        </bean>
    
        <bean id="aTarget" class="A" parent="baseService"/>
    
        <bean id="a" parent="txService">
            <property name="proxyTargetClass" value="false" />
            <property name="optimize" value="false" />
            <property name="target">
                <ref bean="aTarget"/>
            </property>
            <property name="proxyInterfaces">
                <list>
                    <value type="java.lang.Class">IA</value>
                </list>
            </property>
        </bean>
    I am not using cglib but I only use the jdk proxy.
    The method a.getTxCurrentB() calls the preInterceptos and postInterceptor, it is correct.

    The method a.savaTxC(c) calls the preInterceptos and postInterceptor, it is correct.

    But if the method a.saveTxC(c) is called, the inner getTxCurrentB() is called too but its attached interceptors are not called.

    The interceptors have different behaviours for each method.

    I need to know if it's possible that inner getTxCurrentB() has the interceptor available when calling from a.savaTxC(c).



    Thanks a lot.

  • #2
    That's very popular problem that is discussed in details here and at the forum as well.

    Solution is to use aspectj weaving in order to advice internal method calls.

    Comment

    Working...
    X