切面

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;public class MyAspect implements MethodInterceptor{@Overridepublic Object invoke(MethodInvocation mi) throws Throwable {System.out.println("前");// 手动执行目标方法Object obj = mi.proceed();System.out.println("后");return obj;}
}

接口

public interface UserService {void addUser();void updateUser();
}

实现类

public class UserServiceImpl implements UserService {@Overridepublic void addUser() {System.out.println("config adduser...");}@Overridepublic void updateUser() {System.out.println("config updateUser...");}
}

配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><!-- 1.创建目标类 --><bean id="userService" class="com.atchina.c_spring_aop.UserServiceImpl"/><!-- 2.创建切面类 --><bean id="myAspect" class="com.atchina.c_spring_aop.MyAspect"/><!-- 3. aop编程使用<aop:config>配置<aop:pointcut> 切入点<aop:advisor>特殊的切面advice-ref=""  通知的引用pointcut-ref="" 切入点的引用expression="" 切入点表达式--> <aop:config><aop:pointcut expression="execution(* *.*(..))" id="myPointCut"/><aop:advisor advice-ref="myAspect" pointcut-ref="myPointCut" /></aop:config>
</beans>

测试类:

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class TestFactoryBean {@Testpublic void test(){String xmlPath = "com/atchina/c_spring_aop/applicationContext.xml";ApplicationContext ac = new ClassPathXmlApplicationContext(xmlPath);UserService userService = (UserService)ac.getBean("userService");userService.addUser();}
}

spring18-4: spring aop相关推荐

  1. Spring AOP + Redis解决重复提交的问题

    Spring AOP + Redis解决重复提交的问题 用户在点击操作的时候,可能会连续点击多次,虽然前端可以通过设置按钮的disable的属性来控制按钮不可连续点击,但是如果别人拿到请求进行模拟,依 ...

  2. 利用Spring AOP与JAVA注解为系统增加日志功能

    Spring AOP一直是Spring的一个比较有特色的功能,利用它可以在现有的代码的任何地方,嵌入我们所想的逻辑功能,并且不需要改变我们现有的代码结构. 鉴于此,现在的系统已经完成了所有的功能的开发 ...

  3. Spring AOP的一些概念

            切面(Aspect): 一个关注点的模块化,这个关注点可能会横切多个对象.事务管理是J2EE应用中一个关于横切关注点的很好的例子. 在Spring AOP中,切面可以使用通用类(基于模 ...

  4. Spring AOP与IOC

    Spring AOP实现日志服务 pom.xml需要的jar <dependency><groupId>org.apache.commons</groupId>&l ...

  5. Spring AOP与IOC以及自定义注解

    Spring AOP实现日志服务 pom.xml需要的jar <dependency><groupId>org.apache.commons</groupId>&l ...

  6. Spring Aop的应用

    2019独角兽企业重金招聘Python工程师标准>>> AOP的基本概念 连接点( Jointpoint) : 表示需要在程序中插入横切关注点的扩展点,连接点可能是类初始化.方法执行 ...

  7. Spring AOP详解(转载)所需要的包

    上一篇文章中,<Spring Aop详解(转载)>里的代码都可以运行,只是包比较多,中间缺少了几个相应的包,根据报错,几经百度搜索,终于补全了所有包. 截图如下: 在主测试类里面,有人怀疑 ...

  8. 关于spring aop Advisor排序问题

    关于spring aop Advisor排序问题 当我们使用多个Advisor的时候有时候需要排序,这时候可以用注解org.springframework.core.annotation.Order或 ...

  9. 利用spring aop统一处理异常和打日志

    利用spring aop统一处理异常和打日志 spring aop的概念,很早就写博客介绍了,现在在工作中真正使用. 我们很容易写出的代码 我们很容易写出带有很多try catch 和 logger. ...

  10. 我所理解的Spring AOP的基本概念

    Spring AOP中的概念晦涩难懂,读官方文档更是像读天书,看了很多例子后,写一些自己理解的一些spring的概念.要理解面向切面编程,要首先理解代理模式和动态代理模式. 假设一个OA系统中的一个功 ...

最新文章

  1. 利用systemd 实现 tomcat 多实例
  2. HashSet.contains
  3. yelee主题有时候出现背景完全空白的问题
  4. .NET 搭建简单的通知服务
  5. 大数据的发展体现在哪些方面
  6. 【面经】关于Transformer,面试官们都怎么问
  7. Stream介绍及简单操作!
  8. lisp取消选集选中状态_为什么对话框创建后是隐藏状态的
  9. 【C语言开源项目】盘点 GitHub 上不错的 4 个C语言项目
  10. 高数+信号与系统的公式大全,文末附赠有数字信号处理的复习资料哦
  11. VMware虚拟机安装Win10教程
  12. down mark 打钩_[MarkDown] markdown语法小结
  13. 苹果手机验真假_别再被坑了,这3大技巧可辨别真假iPhone,懂得话赚大了
  14. 微信小程序下载图片获取相册授权,保存视频或图片到手机相册
  15. Win系统上最好用的epub阅读器
  16. Arduino IDE+_Attiny13/85实践(一) IED环境配置
  17. 小兵物语---短篇小说
  18. 深度学习入门笔记(八):深层网络的原理
  19. 战舰STM32控制L9110电机驱动
  20. 计算机软件及英文名,计算机技术与软件专业技术资格(水平)考试 各级别 英文名...

热门文章

  1. [web 安全] php随机数安全问题
  2. [转载]明天的数字营销分析工具2
  3. 打算把我的视频工具整合一下
  4. 图片裁剪功能学习小结
  5. linux命令(51):set 指定行,直接替换并修改文件
  6. 从mongodb中查询数据
  7. (39.3) Spring Boot Shiro权限管理【从零开始学Spring Boot】
  8. JSON和JSONP【JS+AJAX跨域原理和实现】
  9. MED-V桌面虚拟化之二配置Template Server(1)
  10. 使用文档自动保存功能