@DeclareParents声明对象的AOP
今天在使用@DeclareParents时,使用AspectJ拓展对象的接口
public interface Encoreable {
void nextPerformance();
}
@Component
public class DefaultEncoreablePerform implements Encoreable {
@Override
public void nextPerformance() {
System.out.println("这是一场返场表演");
}
}
public interface Performance {
public void perform(int num);
}
@Component
public class MusicPerformance implements Performance { @Override
public void perform(int num) {
if (num > 0) {
System.out.println(1 / num);
} else {
System.out.println("Concurred Exception ");
throw new NumberFormatException();
} System.out.println("精彩的表演");
}
}
@Configuration
@ComponentScan
@EnableAspectJAutoProxy
public class ConfigAop {
} @Aspect
@Component
public class AddAspectAudience { @DeclareParents(value = "Performance+", defaultImpl = DefaultEncoreablePerform.class)
public static Encoreable encoreable;
} @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = com.aop.ConfigAop.class)
public class AopAspectjTest { @Autowired
private Performance performance; @Test
public void testAop() {
performance.perform(1);
Encoreable encoreable = (Encoreable) (performance);
encoreable.nextPerformance(); } }
测试时一直提示对象不能强转,找半天找不到原因不知道为什么,暂时记一下
@DeclareParents声明对象的AOP的更多相关文章
- Spring框架学习笔记(7)——代理对象实现AOP
AOP(面向切面编程) AOP(Aspect-Oriented Programming, 面向切面编程): 是一种新的方法论, 是对传统 OOP(Object-Oriented Programming ...
- 样式声明对象:document.styleSheets[0].rules[4].style;
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 深入探究Java中的对象类型变量声明操作——在声明对象时,系统究竟做了什么?
深入探究Java中的对象类型变量声明操作--在声明对象时,系统究竟做了什么? 摘要:本文主要对Java中的对象类型变量的声明的底层原理做了探究. 目录 深入探究Java中的对象类型变量声明操作--在声 ...
- 不是什么时候都可以用栈来声明对象并使用(自动释放)——Delphi里到处都是编译器魔法,并且自动帮助实例化界面元素指针
一直都喜欢这样显示窗口,因为简单高效: void MainWidget::ShowMyWindow() { MyWidget form(this); form.resize(,); form.exec ...
- javascript声明对象时 带var和不带var的区别
2015/11/25补充: 关于变量声明这里有详细的解释: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Stat ...
- AngularJS一个由于未声明对象而报的错
实现这样的一个需求:点击某个按钮,然后显示或隐藏某块区域. 先注册一个AngularJS的一个module: var myApp = angular.module("myApp", ...
- 声明对象的方式/构造函数/原型/this指向
函数的发展历程(声明函数的方式): 1.通过Object构造函数或字面量的方式创建单个对象 var obj = new Object; obj.name="新华"; o ...
- es6声明对象以及作用域与es5对比
es6声明变量: let x=1;//声明一个变量 const y=2;//声明一个只读常量,声明时必须赋值,之后值不可修改 es5声明变量: var z=3;//声明一个变量 区别: let不存在变 ...
- js声明 对象,数组 的方法
i={} 对象字面量 等同 i = new Object();i=[] 数组字面量 等同 i = new Array();
- C#在声明对象时对其赋值的一种方式
今天学会一种更方便的赋值方式,如下, 同时存档一个通过 打开对话框 获取地址的方式. private string GetSaveAsPathXls(string defaultFileName) { ...
随机推荐
- vue super flow 多种形状
1 <template> 2 <v-container class="workflow-container" grid-list-xl fluid> 3 & ...
- SAP 没有开工的产线 闲置成本 处理方案
SAP 没有开工的产线 闲置成本 处理方案 需要沟通的请联系 wx :erpworld
- Linux基本概念
目录 1. 内核.内核态和用户态 2. 用户和组 3. 文件和文件系统 4. I/O模型 5. 程序.进程.线程和协程 6. shell.终端和会话 1. 内核.内核态和用户态 内核是指管理和分配 ...
- [BalticOI 2017] Cat in a tree
[BalticOI 2017] Cat in a tree 神仙美少女 Tweetuzki 学姐用了长剖+线段树,私以为长剖可以做到线性. 简要题意 给定 \(n\) 个点的树,点集 \(S\) 合法 ...
- 语言-页面-模板-Velocity
Velocity教程 - 简书 (jianshu.com) Velocity模板引擎详解 - Velocity 教程 | 编程字典 (codingdict.com) Velocity模板(VM)语言介 ...
- NAT的转换
NAT的转换 拓扑图 Sever0的IP地址:192.168.0.1/24 网关:192.168.0.254 PC0的IP地址:192.168.0.100/24 PC1的IP地址:192.168.0. ...
- lui - pager - 分页
pager - 分页 demo lui demo <template> <div class="app-container"> <h3>el-p ...
- 多个git账户ssh密钥配置
假设两git网站:A.com和B.com,在这两个网站上使用的邮箱和用户名分别为a@mail, userA和b@mail, userB. 清除全局配置 git config --global --li ...
- Redis基础命令和持久化
Redis命令工具 Redis-server :用于启动Redis的工具 Redis-benchmark:用于检查Redis在本机的运行效率 Redis-check-aof:修复aof持久化文件 Re ...
- [OC] 链式语法
我们新建了一个类,叫做 OJClass (这可以是 ViewController,UIView,NSObject 等各种类型的类,这里我们把它以UIView进行举例) 现在我们想要用链式语法的方式来设 ...