45

I am moving from an xml config to annoations. i want to convert a session scoped bean that is

<aop:scoped-proxy>

can this be done with annotations, and if not, what can i do to still keep that declaration working?

edit: I am interested in doing this in Spring 2.5

mkoryak
  • 57,086
  • 61
  • 201
  • 257

3 Answers3

92

In Spring 3.0 it can be specified by the proxyMode attribute of @Scope annotation:

@Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
axtavt
  • 239,438
  • 41
  • 511
  • 482
  • proxyMode is not a field of Scope. is this for 3.0? – mkoryak Dec 21 '10 at 22:37
  • 1
    @mkoryak yup, it's not there in 2.5: http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/context/annotation/Scope.html but it's in 3.0: http://static.springsource.org/spring/docs/3.0.x/javadoc-api/org/springframework/context/annotation/Scope.html – Sean Patrick Floyd Dec 21 '10 at 23:16
  • current I found this document https://docs.spring.io/spring-javaconfig/docs/1.0.0.M4/javadoc-api/org/springframework/config/java/annotation/aop/ScopedProxy.html#:~:text=Annotation%20Type%20ScopedProxy&text=Marker%20annotation%20identical%20in%20functionality,to%20the%20backing%2C%20scoped%20beans – duyetpt Apr 14 '22 at 00:01
8

in the spring context xml, do something like:

<context:component-scan base-package="com.startup.failure" scoped-proxy="interfaces" />

Note that you would need to write interfaces for all classes in that package, though.

sfultong
  • 142
  • 1
  • 4
4

In Spring 2.5.x

If I do in spring-context.xml something like

<context:component-scan base-package="com.startup.failure" scoped-proxy="TARGET_CLASS" />

So this way I don't need my proxied beans to implement interfaces? (using CGLIB not JDK standard). Didn't tested this but i think it should work. Of course you need to have cglib library, you need it with <aop:scoped-proxy> anyway.

Ondrej Bozek
  • 10,987
  • 7
  • 54
  • 70