spring-AOP 增强接口Introductions
第一步:引入JAR
<dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.2.4.RELEASE</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjrt</artifactId><version>1.9.5</version></dependency><!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver --><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.9.5</version></dependency>
</dependencies>
第二步:编写增强接口和实现
public interface MyIntroductions {void introductionsSay();
}
@Component
public class MyIntroductionsImpl implements MyIntroductions {public void introductionsSay() {System.out.println("MyIntroductionsImpl--->introductionsSay");}
}
第三步:编写业务类
@Component("myBusiness")
public class MyBusiness {}
第四步:编写切面业务
@Component
@Aspect
public class MyAspectj {@DeclareParents(value="com.xdw.my.spring.aop.introductions.*+", defaultImpl=MyIntroductionsImpl.class)public static MyIntroductions mixin;
}
第五步:开启注解
@Configuration
@EnableAspectJAutoProxy
@ComponentScan("com.xdw.my.spring.aop.introductions")
public class MyConfiguration {public static void main(String[] args) {AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(MyConfiguration.class);MyIntroductions myIntroductions = (MyIntroductions) annotationConfigApplicationContext.getBean("myBusiness");myIntroductions.introductionsSay();}
}
注意这边获取的对象
测试结果
spring-AOP 增强接口Introductions相关推荐
- Spring AOP 增强框架 Nepxion Matrix 详解
点击上方"方志朋",选择"置顶或者星标" 你的关注意义重大! 概述 在<深入聊一聊 Spring AOP 实现机制>一文中,介绍了 Spring A ...
- Spring AOP增强(Advice)
Sring AOP通过PointCut来指定在那些类的那些方法上织入横切逻辑,通过Advice来指定在切点上具体做什么事情.如方法前做什么,方法后做什么,抛出异常做什么. 再来看一下图 定义Point ...
- Spring AOP代理时 ClassCastException: $Proxy0 cannot be cast to (类型转换错误)
Spring AOP代理时 ClassCastException: $Proxy0 cannot be cast to (类型转换错误) 问题: 今天在用AfterReturningAdvice时,a ...
- spring aop代码的增强
这篇博客,主要会分析spring aop是如何实现代码增强的. 从上一篇博客 我们大概知道,spring能在不改变代码的前提下,往一个方法的之前和之后添加代码. 想下,java中有哪种技术可以帮我们实 ...
- Spring : Spring AOP 中的增强(Advice)或者通知
1.美图 2.概述 概念参考:Spring :Spring AOP 中的一些术语 很多人将增强理解为通知,但是理解为增强会更加准确,因为它表示在连接点上执行的行为,这个行为是目标类类所没有的,是为目标 ...
- 【spring aop】连接点(Jointpoint)、切入点(Pointcut)、增强(Advice)、方面/切面(Aspect、Advisor)
文章目录 前言 1. 先来回顾一下AOP中的一些术语 2. 增强方式简介 2.1 MethodBeforeAdvice前置增强 2.2 AfterReturningAdvice后置增强 2.3 Thr ...
- Spring AOP(二)AOPAlliance与SpringAOP核心接口介绍
目录 AOP联盟 1. Advice.MethodInterceptor拦截器(invoke方法:调用invocation.proceed) 2.Joinpoint .MethodInvocation ...
- spring AOP原理分析:静态代理;JDK实现接口动态代理;Cglib继承父类代理;SpringAop的责任链模式调用
普通静态代理 代理类和真实类都需要实现同一个接口 接口 package com.fchan.layui.represent.service; /*** 静态代理demo*/ public interf ...
- android aop静态方法,spring aop 不能对静态方法进行增强解决
想要通过aop的方式记录HttpUtils发出的post请求日志,但是 aop 不能对静态方法进行增强.只能对实例方法进行增强.. 如果一定要增强静态方法,我们可以对目标类使用单例模式,然后通过调用实 ...
- spring aop 会根据实际情况(有无接口)自动选择 两种 动态代理(jdk和cglib)之一...
资料: (1)Cglib的简单使用: https://blog.csdn.net/zhanghongjie0302/article/details/45648947 (2)关于java字节码框架ASM ...
最新文章
- uniapp在安卓和IOS端 APP固定竖屏及获取设备信息
- spark指定hive字段_Spark2.0集成Hive操作的相关配置与注意事项
- zz让你成功的九个心理定律
- 超出网络bios会话限制_如何设置网络以防止数据丢失
- Spring Boot快速搭建入门程序
- LeetCode:922. 按奇偶排序数组 II
- canvas 绘制圆形进度条
- 计量经济学笔记1-Eviews操作-一元线性回归
- 图像处理算法:最大类间方差法
- groovy curry的用处
- python刷题记录:买帽子
- Excel-DATEDIF函数计算两日期天数差
- DAY11:尚学堂高琪JAVA(116~118)
- 勿以自己的经历来审视他人
- # 计算机科学导论习题见解(机械工业)
- 如何优雅判断属性值为空
- un直连服务器教程,UNRAID 搭建Rocket.Chat 私有聊天服务器教程
- 在AWS上部署一个网站
- Spring Boot之使用JPA保存数据
- Android 基本适配器BaseAdapter
热门文章
- 独立服务器和云服务器的分类以及是如何区分的?
- COM in Wine(1)——COM基本概念
- Some WSL system related access rights are not set correctly. This sometimes happens after waking the
- matplotlib.pyplot 绘制图中图
- pointer在html作用,html-CSS中的“ cursor:pointer”效果为什么不起作用
- Diligent调查发现,董事会成员是安全和公司治理的关键环节
- QML类型:Window
- 云计算机运用 技术,云计算技术在计算机数据处理中的应用
- DAY1:尚学堂高琪JAVA(1~20)
- 一个SAP开发人员的双截棍之路