spring 相当于 <aop:scoped-proxy> 的注释

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4503606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 04:16:05  来源:igfitidea点击:

annotation equivalent of <aop:scoped-proxy>

springspring-aop

提问by mkoryak

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

我正在从 xml 配置转向 annoations。我想转换一个会话范围的bean

<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

编辑:我有兴趣在 Spring 2.5 中执行此操作

采纳答案by sfultong

in the spring context xml, do something like:

在 spring 上下文 xml 中,执行以下操作:

<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.

请注意,您需要为该包中的所有类编写接口。

回答by axtavt

In Spring 3.0 it can be specified by the proxyModeattribute of @Scopeannotation:

在 Spring 3.0 中可以通过注解的proxyMode属性来指定@Scope

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

回答by Ondrej Bozek

In Spring 2.5.x

在 Spring 2.5.x 中

If I do in spring-context.xml something like

如果我在 spring-context.xml 中做类似的事情

<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.

那么这样我就不需要我的代理 bean 来实现接口了吗?(使用 CGLIB 不是 JDK 标准)。没有测试这个,但我认为它应该工作。当然你需要有 cglib 库,<aop:scoped-proxy>无论如何你都需要它。