Announcement Announcement Module
Collapse
No announcement yet.
proxy an already proxied object? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • proxy an already proxied object?

    I have a business object which is proxied to have transaction support as follows:

    <bean id="myManager" parent="txProxyTemplate">
    <property name="target">
    <bean class=example.impl.myManagerImpl">
    <property name="myDao">
    <ref bean="myDao"/>
    </property>
    </bean>
    </property>
    </bean>

    Then I want to log invocation of its methods. So I use ProxyFactoryBean
    to set myManager as its target, but the applcation always failed to
    start up and report error message:

    Initialization of bean failed; nested exception is org.aopalliance.aop.AspectException: null
    java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy1
    at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer .java:442)
    at net.sf.cglib.transform.TransformingClassGenerator. generateClass(TransformingClassGenerator.java:33)
    at net.sf.cglib.core.DefaultGeneratorStrategy.generat e(DefaultGeneratorStrategy.java:25)
    at net.sf.cglib.core.AbstractClassGenerator.create(Ab stractClassGenerator.java:215)
    at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer. java:373)
    .....

    It seems to me that such proxied business objects cannot be proxied
    again. Correct?

    Then I tried the following:

    <bean id="myAutoProxyCreator"
    class="org.springframework.aop.framework.autoproxy .BeanNameAutoProxyCreator">
    <property name="beanNames">
    <value>*Manager</value>
    </property>
    <property name="interceptorNames">
    <list>
    <idref bean="myInterceptor"/>
    </list>
    </property>
    </bean>

    However the interceptor did get called before or after the methods of
    myManager.

    I read online docs and tested many times, but could not get
    what I want.

    Please help.

    Regards, Pete

  • #2
    Then I want to log invocation of its methods.
    Sounds like you just need to add another interceptor to your list.
    Code:
    <property name="interceptorNames">
      <list>
        <value>myInterceptor</value>
        <value>myLogInterceptor</value>
      </list>
    </property>
    If you swapped from ProxyFactoryBean to TransactionProxyFactoryBean you can do the saem with pre/post interceptors.
    Code:
    <property name="postInterceptors">
      <list>
        <ref local="myLogInterceptor"/>
      </list>
    </property>

    Comment


    • #3
      katentim,

      thanks for your input.

      in my post, myInterceptor is THE log interceptor. sorry for being not very clear.

      If you swapped from ProxyFactoryBean to TransactionProxyFactoryBean you can do the saem with pre/post interceptors.
      do you mean i can directly add pre/post interceptors to TransactionProxyFactoryBean-proxy via its pre/postInterceptors property instead of using ProxyFactoryBean? i want to try it.

      here is another question: what if i want to log an exception? does the TransactionProxyFactoryBean's postInterceptor property accept a ThrowsAdvice interceptor?

      thanks a lot!

      regards,
      pete

      Comment


      • #4
        do you mean i can directly add pre/post interceptors to TransactionProxyFactoryBean-proxy via its pre/postInterceptors property instead of using ProxyFactoryBean?
        Yes

        does the TransactionProxyFactoryBean's postInterceptor property accept a ThrowsAdvice interceptor?
        Yes

        Comment


        • #5
          katentim,

          thanks very much for your help!
          have a great weekend.

          regards, pete

          Comment

          Working...
          X