Announcement Announcement Module
No announcement yet.
@ScopedProxy or annotation equivalent of <aop:scoped-proxy/> Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ScopedProxy or annotation equivalent of <aop:scoped-proxy/>

    Are there any plans to introduce an Java annotation equivalent of the <aop:scoped-proxy/> at some point?

  • #2
    It seems to exist but only as part of Spring Java Config.



    • #3
      Yes, I found that too. However it's not really what I was looking for. That would require me to write a separate Java class similar to using the separate XML based configuration. I don't see the advantage. When you write the annotations directly into the original class it keeps everything in one place so it's simpler.


      • #4
        Originally posted by jdhwpgmbca View Post
        That would require me to write a separate Java class similar to using the separate XML based configuration.
        I can't follow you. Why could you not just add the annotation to the actual to-be-proxied class?



        • #5
          I too am interested in this.

          Originally posted by Jörg Heinicke View Post
          Why could you not just add the annotation to the actual to-be-proxied class?
          Spring Java Config annotations cannot be used in this way, they are used only as a part of java class that represents the whole java configuration, as opposed to xml config.

          So, we need something like @ScopedProxy that works on individual beans, together with @Component and @Scope.


          • #6
            After some digging I found the solution. You define component-scan definition like this:
            HTML Code:
            <context:component-scan base-package="your.package" scoped-proxy="interfaces"/>
            All scoped beans will then be automaticaly proxied. It seems that the default value of "scoped-proxy" attribute is "no", which would mean no proxies would be created.

            The possible values for "scoped-proxy" attribute are: "no", "interfaces" and "targetClass".



            • #7
              <context:component-scan base-package="your.package" scoped-proxy="interfaces"/>

              Thanks, that works for me. I do like the @ScopedProxy annotation idea better though. This works but you need to be careful to keep your proxied classes separate in some way from your non-proxied ones - probably a different package.
              Last edited by jdhwpgmbca; Nov 22nd, 2007, 09:40 PM.


              • #8
                scoped-proxy=&quot;interfaces&quot; creates 'standard JDK proxies'

                Don't forget that scoped-proxy="interfaces" creates 'standard JDK proxies'

                This is different from the default for "<aop:scoped-proxy/>" which creates CGLIB based proxies.

                As a result your scoped bean needs to implement an interface and all your collaborators have to reference the interface.



                • #9
                  @scope and jsp


                  When you place a bean in the session using the @scope.
                  How do you access to it in the jsp page ?

                  I would like to kwon if a value is store in the http session and how the get the name of the object in the session



                  • #10
                    what sense does it make to use request/session-scoped beans without <aop:scoped-proxy/>? Shouldn't Spring either activate that as a default or throw an exception? I currently have "request" scoped beans running that get passed from request to request.... (Spring 3.0.7)


                    • #11
                      I know this thread is old, but this was added to the @Scope annotation in Spring 3.0

                      For example:

                      @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)


                      • #12
                        Exception in CGLIB evaluating toString on scoped bean proxy

                        I am having a problem with this. I am using the exact annotation you have provided but I cannot seem to reference the scoped bean from within a filter.

                        In my web.xml I declare the filter like so:

                        Then declare my filter bean:

                        @Component(value = "apiFilter")
                        public class ApiAuthFilter extends GenericFilterBean {
                        And my scoped bean:

                        @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
                        public class UserSession implements Serializable {
                        But when I inject my scoped bean into the Filter as soon as the filter is hit I get this error:

                        Method threw 'org.springframework.beans.factory.BeanCreationException' exception.  Cannot evaluate com.mypackage.UserSession$$EnhancerByCGLIB$$c52125bc.toString()
                        The "toString()" method of my scoped bean is not even implemented.

                        Is this a bug?


                        • #13
                          I like @ScopedProxy