随笔 - 395  文章 - 3  评论 - 49  阅读 - 85万

aop:declare-parents注解

http://www.blogjava.net/jackfrued/archive/2010/02/27/314060.html

1 <aop:aspect>
2     <aop:declare-parents
3          types-matching="com.springinaction.springidol.Performer+"
4          implement-interface="com.springinaction.springidol.Contestant"
5           default-impl="com.springinaction.springidol.GraciousContestant"
6      />
7 </aop:aspect>

 

或者用委托代理

复制代码
1 <aop:aspect>
2     <aop:declare-parents
3          types-matching="com.springinaction.springidol.Performer+"
4          implement-interface="com.springinaction.springidol.Contestant"
5          delegate-ref="contestantDelegate"
6 </aop:aspect>
7 
8 
9 <bean id="contestantDelegate" class="com.springidol.GraciousContestant">
复制代码

 

目标是 types-matching的类,spring让它实现 implement-interface所指向的接口, 而具体实现则通过default-impl属性来赋予。

 

所以 让 types-matching 的类添加了 接口并且指定了实现。

所以从spring容器中拿出来的 performer 对象   可以被强转换成 Contestant 类型的对象。如果调用Contestant的方法必须要强转,因为这些都是spring背后做了很多事情。而不是代码显示地继承了它的接口。

posted on   wf110  阅读(1697)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示