annotation equivalent of

2019-01-13 07:28发布

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

3条回答
2楼-- · 2019-01-13 07:55

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

@Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
查看更多
地球回转人心会变
3楼-- · 2019-01-13 07:59

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.

查看更多
Fickle 薄情
4楼-- · 2019-01-13 08:10

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.

查看更多
登录 后发表回答