Announcement Announcement Module
Collapse
No announcement yet.
Using CGLIB and dynamic proxies for different @Aspect's Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using CGLIB and dynamic proxies for different @Aspect's

    I have some classes (Webwork actions) that doesn't like to be proxied using dynamic proxies(Webwork doesn't support it).
    So, I guess what I need to do is use CGLIB for the Webwork actions and dynamic proxies for all other classes.
    How do I accomplish that?
    Until now, I've been using <aop:aspectj-autoproxy /> because it's so convenient.

    I'm using Spring 2.0-RC3.

  • #2
    Originally posted by Wesslan
    I have some classes (Webwork actions) that doesn't like to be proxied using dynamic proxies(Webwork doesn't support it).
    So, I guess what I need to do is use CGLIB for the Webwork actions and dynamic proxies for all other classes.
    How do I accomplish that?

    I'm using Spring 2.0-RC3.
    Wrap your Webwork aspects with:

    Code:
    
    <aop:config proxy-target-class="true">
    </aop:config>

    Comment


    • #3
      Originally posted by cepage
      Wrap your Webwork aspects with:

      Code:
      
      <aop:config proxy-target-class="true">
      </aop:config>
      So I can still use
      Code:
      <aop:aspectj-autoproxy />
      for my other beans?

      Comment


      • #4
        Originally posted by Wesslan
        So I can still use
        Code:
        <aop:aspectj-autoproxy />
        for my other beans?
        I believe so. I would probably strip the annotations off of the Webwork Actions so that <aop:aspectj-autoproxy/> doesn't try to take a crack at them, too.

        Comment


        • #5
          Originally posted by cepage
          I believe so. I would probably strip the annotations off of the Webwork Actions so that <aop:aspectj-autoproxy/> doesn't try to take a crack at them, too.
          Hmm, it's not the Webwork actions that are annotated, it's my aspects.
          Code:
          @Aspect
          public class ProfilingAspect {
          ...
          }
          Sure, I can change my pointcut expressions to not include the Webwork actions and then make separate poincut expressions for them in Spring XML but that's not very elegant.

          Comment


          • #6
            Originally posted by Wesslan
            Sure, I can change my pointcut expressions to not include the Webwork actions and then make separate poincut expressions for them in Spring XML but that's not very elegant.
            The alternative is to define a set of overlapping pointcuts, and punt to Spring to figure out the 'right' thing to do. I can't speak to whether or not that is elegant, but it certainly seems sloppy to me.

            The Spring team models a set of best practices where you define a set of named pointcuts for defined layers of your application, such as Webwork Actions. Your CGLIB pointcut expression would include the named pointcut for your Webwork Layer, whereas your autoproxied ProfilingAspect would not.

            Comment


            • #7
              Originally posted by cepage
              The Spring team models a set of best practices where you define a set of named pointcuts for defined layers of your application, such as Webwork Actions. Your CGLIB pointcut expression would include the named pointcut for your Webwork Layer, whereas your autoproxied ProfilingAspect would not.
              What you said made totally sense so I tried it...
              First, I tried it with
              Code:
              <aop:aspectj-autoproxy proxy-target-class="false"/>
              
              <aop:config proxy-target-class="true">
                <aop:aspect id="profilingAspectWebworkActions" ref="profilingAspectBean">
                   <aop:around method="logIt" pointcut="com.foo.myapp.SystemArchitecture.webService()"/>
                </aop:aspect>
              </aop:config>
              but then I got errors saying "Unable to proxy method *whatever* because it is final: All calls to this method via a proxy will be routed directly to the proxy."

              Then I tried it with (NOTE: No <aop:aspectj-autoproxy proxy-target-class="false"/>)
              Code:
              <aop:config proxy-target-class="true">
                <aop:aspect id="profilingAspectWebworkActions" ref="profilingAspectBean">
                   <aop:around method="logIt" pointcut="com.foo.myapp.SystemArchitecture.webService()"/>
                </aop:aspect>
              </aop:config>
              
              <aop:config proxy-target-class="false">
                <aop:aspect id="profilingAspectBusinessServices" ref="profilingAspectBean">
                   <aop:around method="logIt" pointcut="com.foo.myapp.SystemArchitecture.businessService()"/>
                </aop:aspect>
              </aop:config>
              but again, the same errors appeared.
              It seems that if you have one aop:config with proxy-target-class="true" CGLIB will be used for everything.
              Thoughts?

              Thanks,
              Peter

              Comment


              • #8
                I found a Jira about something like this.
                See Rob's second answer:
                "You cannot enable/disable target class proxying in invidual blocks. If one block uses it so do all the others."

                Is this still valid for Spring-RC3?

                Comment


                • #9
                  Originally posted by Wesslan
                  I found a Jira about something like this.
                  See Rob's second answer:
                  "You cannot enable/disable target class proxying in invidual blocks. If one block uses it so do all the others."

                  Is this still valid for Spring-RC3?
                  What a pain. That's a pretty nasty bug. I would post onto the Jira issue, asking Juergen to reopen it, and post a config excerpt that triggers the problem.

                  Comment


                  • #10
                    I didn't think that the existing Jira was exactly what I have problems with so I created a new one here.

                    Comment


                    • #11
                      Originally posted by Wesslan
                      but then I got errors saying "Unable to proxy method *whatever* because it is final: All calls to this method via a proxy will be routed directly to the proxy."
                      This is a restriction of the Java language; you cannot override methods that are final, or a class that is final.

                      By not using a proxy you are effectively asking CGLIB to create a subclass of your class....it can only work if the class isn't final and it can then only override methods that are not final.

                      Be thankful that you at least got an error message....Some other well known frameworks silently fail in this scenario

                      Comment


                      • #12
                        Originally posted by yatesco
                        This is a restriction of the Java language; you cannot override methods that are final, or a class that is final.
                        By not using a proxy you are effectively asking CGLIB to create a subclass of your class....it can only work if the class isn't final and it can then only override methods that are not final.
                        Yes, I'm fully aware of this and that's why I have to use dynamic proxies some of the classes.

                        Originally posted by yatesco
                        Be thankful that you at least got an error message....Some other well known frameworks silently fail in this scenario
                        I'm so thankful.

                        Comment


                        • #13


                          The other approach you could use is using the "old style" ProxyFactoryBeans....

                          Comment


                          • #14
                            Originally posted by yatesco
                            The other approach you could use is using the "old style" ProxyFactoryBeans....
                            Ah, didn't think of that. Even if it would be quite boring to set up all of my proxied beans that way...

                            Still thankful though!

                            Comment

                            Working...
                            X