例子、

     接口
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. 在JDBC中使用带参数的SQL语句

    ADO.Net中,支持带参数的SQL语句,例如:Select * from Tables where column1=@column1,其中@column1为SQL参数,使用起来非常方便,而JDBC中 ...

  2. ctfshow--web3 incluede伪协议注入

    这题一看就知道是个伪协议的题 直接用data伪协议 ls 查看目录 data://text/plainy, 再cat 一下就拿到flag了

  3. solon-flow 你好世界!

    solon-flow 是一个基础级的流处理引擎(可用于业务规则.决策处理.计算编排.流程审批等......).提供有 "开放式" 驱动定制支持,像 jdbc 有 mysql 或 p ...

  4. 谈谈天翼云VPCE

    本文分享自天翼云开发者社区<谈谈天翼云VPCE>,作者:天枫霁月 一.VPCE产品出现的背景 跨VPC通信,且能够严格限制访问,任意两个租户之间都能互通,性能高,花费少,通过VPCE产品实 ...

  5. Q:xml 需要转义的字符

    XML实体中不允许出现"&","<",">"等特殊字符,否则XML语法检查时将出错,如果编写的XML文件必须包含这些字符 ...

  6. Iceberg问题记录-数据湖问题记录跟进

    一.问题追踪 问题 详细描述 提出问题时间 是否完成 计划完成时间 备注 了解Iceberg数据存储方式 了解元数据存储信息.数据组织方式.查询时处理流程等 20231013 是 20231019 ! ...

  7. [SHOI2017] 摧毁“树状图”

    首先只要得到 \(x=0\) 时的答案,就可以 \(AC\) 本题.这是很重要的. 考虑由于不能有重复经过的边,所以两路径交点数量 \(\le 1\). 容易想到设 \(dp_u\) 表示以 \(u\ ...

  8. 小米10至尊纪念版—官方稳定版一键 TWRE刷入+面具ROOT

    1.解锁BL http://www.miui.com/unlock/index.html 2.备份+关机(虽然不会清理数据,但是小心为上) 3.音量下+开机进入fastboot模式 4.解压压缩包,运 ...

  9. 大数据之路Week08_day03 (Hive优化)

    Hive优化(下面的红色标记是十分重要的,大部分情况是需要开启的) 优化1:hive的抓取策略理论上来说,Hive中的所有sql都需要进行mapreduce,但是hive的抓取策略帮我们省略掉了这个过 ...

  10. 洛谷P2701 [USACO5.3] 巨大的牛棚Big Barn 题解

    怎么题解全是清一色的 dp?可以用笛卡尔树啊(虽然麻烦了很多,但是我热爱)! 题目传送门. 笛卡尔树的介绍 笛卡尔树,是一种二叉搜索树,它满足如下条件: 每个节点的编号满足二叉搜索树的性质. 每个节点 ...