例子、

     接口
public interface Calculator {
// 加
public int add(int i, int j); // 减
public int sub(int i, int j); // 乘
public int mul(int i, int j); //除
public int div(int i, int j);
} 实现
public class MyMathCalculator implements Calculator {
@Override
public int add(int i, int j) {
int result = i + j;
return result;
} @Override
public int sub(int i, int j) {
int result = i - j;
return result;
} @Override
public int mul(int i, int j) {
int result = i * j;
return result;
} @Override
public int div(int i, int j) {
int result = i / j;
return result;
}
} 切面、 public class LogUtils { public static void logStart(JoinPoint joinPoint){
//获取到目标方法运行是使用的参数
Object[] args = joinPoint.getArgs();
//获取到方法签名
Signature signature = joinPoint.getSignature();
String name = signature.getName();
System.out.println("【"+name+"】方法开始执行,用的参数列表【"+ Arrays.asList(args)+"】");
} public static void logReturn(JoinPoint joinPoint,Object result){
System.out.println("【"+joinPoint.getSignature().getName()+"】方法正常执行完成,计算结果是:"+result);
} public static void logException(JoinPoint joinPoint,Exception exception){
System.out.println("【"+joinPoint.getSignature().getName()+"】方法执行出现异常了,异常信息是【"+exception+"】:;这个异常已经通知测试小组进行排查");
} private int logEnd(JoinPoint joinPoint){
System.out.println("【"+joinPoint.getSignature().getName()+"】方法最终结束了");
return 0;
}
} <?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd"> <!-- 基于注解的AOP步骤;
1、将目标类和切面类都加入到ioc容器中。@Component
2、告诉Spring哪个是切面类。@Aspect
3、在切面类中使用五个通知注解来配置切面中的这些通知方法都何时何地运行
4、开启基于注解的AOP功能
-->
<!-- 开启基于注解的AOP功能;aop名称空间--> <!-- 基于配置的AOP-->
<bean id="myMathCalculator" class="com.apcstudy.aop.impl.MyMathCalculator" />
<bean id="logUtils" class="com.apcstudy.aop.utils.LogUtils" /> <!-- 需要AOP名称空间 -->
<aop:config>
<aop:pointcut id="mypoint" expression="execution(* com.apcstudy.aop.impl.MyMathCalculator.*(..))"/>
<!--告诉Spring哪个是切面类。@Aspect-->
<aop:aspect ref="logUtils">
<aop:before method="logStart" pointcut-ref="mypoint" />
<aop:after-returning method="logReturn" pointcut-ref="mypoint" returning="result" />
<aop:after-throwing method="logException" pointcut-ref="mypoint" throwing="exception" />
<aop:after method="logEnd" pointcut-ref="mypoint" />
</aop:aspect>
</aop:config> <!--注解:快速方便
配置:功能完善;重要的用配置,不重要的用注解;
--> </beans>

使用XML的方式编写:@Aspect运用的更多相关文章

  1. 21_Android中常见对话框,光传感器,通过重力感应器编写出指南针应用,帧动画,通过Jav代码的方式编写补间动画,通过XML的方式编写补间动画

     1 关于常见的对话框,主要有: 常见的对话框,单选对话框,多选对话框,进度条对话框(转圈类型的),带进度条的对话框. 案例结构: 完成如下结构的案例,将所有的案例都测试一下: 2 编写MainA ...

  2. 转-springAOP基于XML配置文件方式

    springAOP基于XML配置文件方式 时间 2014-03-28 20:11:12  CSDN博客 原文  http://blog.csdn.net/yantingmei/article/deta ...

  3. Android中的三种XML解析方式

    在Android中提供了三种解析XML的方式:SAX(Simple API XML),DOM(Document Objrect Model),以及Android推荐的Pull解析方式.下面就对三种解析 ...

  4. struts_20_对Action中所有方法、某一个方法进行输入校验(基于XML配置方式实现输入校验)

    第01步:导包 第02步:配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app ...

  5. struts2视频学习笔记 22-23(基于XML配置方式实现对action的所有方法及部分方法进行校验)

    课时22 基于XML配置方式实现对action的所有方法进行校验   使用基于XML配置方式实现输入校验时,Action也需要继承ActionSupport,并且提供校验文件,校验文件和action类 ...

  6. 【Struts2学习笔记(11)】对action的输入校验和XML配置方式实现对action的全部方法进行输入校验

    在struts2中,我们能够实现对action的全部方法进行校验或者对action的指定方法进行校验. 对于输入校验struts2提供了两种实现方法: 1. 採用手工编写代码实现. 2. 基于XML配 ...

  7. Struts2第十篇【数据校验、代码方式、XML配置方式、错误信息返回样式】

    回顾以前的数据校验 使用一个FormBean对象来封装着web端来过来的数据 维护一个Map集合保存着错误信息-对各个字段进行逻辑判断 //表单提交过来的数据全都是String类型的,birthday ...

  8. 6.AOP配置与应用(xml的方式)

    xml 配置 AOP 1.将 拦截其器对象 初始化到容器中 2.<aop:config> <aop:aspect.... <aop:pointcut <aop:befor ...

  9. hibernate 联合主键生成机制(组合主键XML配置方式)

    hibernate 联合主键生成机制(组合主键XML配置方式)   如果数据库中用多个字段而不仅仅是一个字段作为主键,也就是联合主键,这个时候就可以使用hibernate提供的联合主键生成策略. 具体 ...

  10. web.xml中配置Spring中applicationContext.xml的方式

    2011-11-08 16:29 web.xml中配置Spring中applicationContext.xml的方式 使用web.xml方式加载Spring时,获取Spring applicatio ...

随机推荐

  1. Spring Cloud认知学习(一)--Eureka使用、Ribbon使用

    Spring Cloud是一个微服务架构,他有多种组件来管理微服务的方方面面.Spring Cloud是用于构建微服务开发和治理的框架的集合. Spring Cloud是最热门的Java技术毋庸置疑. ...

  2. Java中的基本数据类型默认值扩展

    因为在很多情况下,如果要转换的数据为null,调用者期望的是返回默认值. 系统自动提供的默认值不能满足我们的需求,例如int的默认值为0,但是在sql查询中,如果查询失败,我们期望的是小于0的值,例如 ...

  3. .NET Core GC压缩(compact_phase)底层原理浅谈

    简介 终于来到了GC的最后一个步骤,在此之间,大量预备工作已经完成.万事俱备,只欠东风 清除 如果GC决定不压缩,它将仅执行清除操作.清除操作非常简单,把所有不可到达对象(gap),转换成Free.也 ...

  4. 某教育网站疑似删库。。。没备份。。。数据全没了。。。Sealos 带你一分钟满血复活

    2025 年 1 月 15 日,微信群里有人爆料,某教育网站疑似删库,导致网站无法访问.具体的问题是数据库被格式化了,而且也没有备份,连数据库表结构都没有,不仅业务瘫痪,也无法拉起新的应用,实在是有点 ...

  5. 深入探讨数据库索引类型:B-tree、Hash、GIN与GiST的对比与应用

    title: 深入探讨数据库索引类型:B-tree.Hash.GIN与GiST的对比与应用 date: 2025/1/26 updated: 2025/1/26 author: cmdragon ex ...

  6. Linux/Centos文件授权用户文件夹权限介绍

    一.Linux文件权限介绍 在Linux中,一切皆为文件(目录也是文件),每个文件对用户具有可读(read).可写(write).可执行(excute)权限.目录的执行操作表示是否有权限进入该目录并操 ...

  7. Q:windows server2019由于没有远程桌面授权服务器可以提供许可证,远程回话连接已断开

    由于没有远程桌面授权服务器可以提供许可证,远程回话连接已断开,请跟服务管理员联系 原因是服务器安装了远程桌面服务RemoteApp,这个是需要授权的.但是微软官方给予了120天免授权使用,超过120天 ...

  8. Hive源码解析环境搭建

    一.准备工作 1.1  下载地址 https://github.com/apache/hive https://dlcdn.apache.org/hive/ 版本:2.3.9 1.2 环境依赖 had ...

  9. 水利地理信息系统 - www.WaterGIS.cn

    用C#语言开发了一个免费GIS软件,可以用来快速浏览和编辑SHAPE文件,支持天地图等. 下载可以去QQ群:722489551

  10. C#如何MeasureString、Graphics获取字符串的像素长度

    1. 当单元格展示的字符串需要自动换行的时候,使用GDI绘制文本信息,需要计算字符串文本的实际高度信息(需要固定宽度) 方法一:代码如下,会出现文本没有挤满当前行,但是文本实际高度已换行. priva ...