今天在使用@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(); } }

测试时一直提示对象不能强转,找半天找不到原因不知道为什么,暂时记一下

最新文章

  1. BZOJ 1087 【SCOI2005】 互不侵犯King
  2. php 下载文件的函数
  3. NK3C 业务权限控制
  4. Web前端小白入门指迷
  5. Android 开发环境下载地址 -- 百度网盘 adt-bundle android-studio sdk adt 下载
  6. UILabel详解
  7. webkit和xcode
  8. Win7_关闭休眠文件hiberfil.sys
  9. CSS3:不可思议的border属性&Web字体图标Font Awesome
  10. 为php安装memcached扩展连接memcached服务器
  11. ajaxfileupload
  12. MessageBox, MessageBoxBurttons, MessageBoxIcon 详细解析
  13. 关于LINUX各类系统资源整合
  14. 基于Spring Cloud、JWT 的微服务权限系统设计
  15. vue结合axios使用入门
  16. mysql插入中文报错的问题
  17. Jexus使用的相关记录
  18. JSON数据写入和解析
  19. 面试加分项---HashMap底层实现原理
  20. 第39章 ETH—Lwip以太网通信

热门文章

  1. p标签设置行数,超出部分用省略号隐藏
  2. [AGC013B] Hamiltonish Path
  3. string转JSONObject顺序不变和 往map放数据按顺序
  4. redis之redisObject对象
  5. ES6的模块化(export导出)
  6. 最长上升子序列(LIS) dp典型例题(tzoj 矩形嵌套,Rectangles )
  7. HCIA-ICT实战基础09-远程接入安全管理
  8. python菜鸟学习: 10. 函数的基本用法
  9. WebService接口实际场景应用(一)
  10. 第三章:用python实现常用的用户分层模型(RFM模型)