Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
680bfbe7
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
680bfbe7
编写于
5月 19, 2010
作者:
O
Oliver Gierke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
SPR-7186 Added section on generic advice parameters
上级
d600e351
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
38 addition
and
0 deletion
+38
-0
spring-framework-reference/src/aop.xml
spring-framework-reference/src/aop.xml
+38
-0
未找到文件。
spring-framework-reference/src/aop.xml
浏览文件 @
680bfbe7
...
...
@@ -1275,6 +1275,44 @@ public void audit(Auditable auditable) {
}
</programlisting>
</section>
<section
id=
"aop-ataspectj-advice-params-generics"
>
<title>
Advice parameters and generics
</title>
<para>
Spring AOP can handle generics used in class declarations and
method parameters. Suppose you have a generic type like this:
</para>
<programlisting
language=
"java"
>
public interface Sample
<
T
>
{
void sampleGenericMethod(T param);
void sampleGenericCollectionMethod(Collection
>
T
>
param);
}
</programlisting>
<para>
You can restrict interception of method types to certain
parameter types by simply typing the advice parameter to the
parameter type you want to intercept the method for:
</para>
<programlisting
language=
"java"
>
@Before("execution(* ..Sample+.sampleGenericMethod(*))
&&
args(param)")
public void beforeSampleMethod(MyType param) {
// Advice implementation
}
</programlisting>
<para>
That this works is pretty obvious as we already discussed
above. However, it's worth pointing out that this won't work for
generic collections. So you cannot define a pointcut like
this:
</para>
<programlisting
language=
"java"
>
@Before("execution(* ..Sample+.sampleGenericCollectionMethod(*))
&&
args(param)")
public void beforeSampleMethod(Collection
<
MyType
>
param) {
// Advice implementation
}
</programlisting>
<para>
To make this work we would have to inspect every element of
the collection, which is not reasonable as we also cannot decide how
to treat
<literal>
null
</literal>
values in general. To achieve
something similar to this you have to type the parameter to
<interfacename>
Collection
<
?
>
</interfacename>
and manually
check the type of the elements.
</para>
</section>
<section
id=
"aop-ataspectj-advice-params-names"
>
<title>
Determining argument names
</title>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录