Results 1 to 2 of 2

Thread: Problem with proxied methods

Hybrid View

  1. #1
    Join Date
    Sep 2009
    Posts
    5

    Cool 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. #2
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    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.

Posting Permissions

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