例子、

     接口
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. 基于FATE的可验证秘密分享算法详解及应用场景分享:学习

    内容来自"光大科技-基于FATE的可验证秘密分享算法详解及应用场景分享" 理论 基于Shamir的秘密共享方案,通过多项式插值实现. 加入可验证功能,即发送多项式系数的模数给对方作 ...

  2. C# as 和 is 运算符区别和用法

    前言 在C#中,as 和 is 关键字都用于处理类型转换的运算符,但它们有不同的用途和行为.本文我们将详细解释这两个运算符的区别和用法. is 运算符 is 运算符用于检查对象是否是某个特定类型,或者 ...

  3. sql server导入表的一些函数使用

    truncate table JC_BMDA; insert into JC_BMDA(bh,mc,qdmc,pym,ty) select right('0'+rtrim(convert(varcha ...

  4. .NET 进程 stackoverflow异常后,还可以接收 TCP 连接请求吗?

    昨天线上有几个进程因为 StackOverFlowException 导致进程 Crash 了,但是 TCP 请求还是可以连接,具体可不可以连接一个出现StackOverFlowException的微 ...

  5. 文本处理命令head tail more less tr cut paste wc

    文本处理命令 命令**head tail more less tr cut paste wc** 磁盘分区利用率 df|tr -s ' ' :|cut -d : -f5 df|tr -s ' ' :| ...

  6. Deepseek学习随笔(10)--- 本地AI神器Cherry Studio & Chatbox 保姆级教程(附网盘链接)

    本篇介绍的 Cherry Studio 和 Chatbox 两款工具,只需简单几步,即可实现本地化部署AI能力,支持对话.编程.绘图等多场景应用.本文将手把手教你从零开始配置使用! 一.软件下载:两步 ...

  7. 《HelloGitHub》第 107 期

    兴趣是最好的老师,HelloGitHub 让你对开源感兴趣! 简介 HelloGitHub 分享 GitHub 上有趣.入门级的开源项目. github.com/521xueweihan/HelloG ...

  8. 【前端解决方案】已有本地项目如何建立github仓库

    步骤 1:在本地初始化 Git(如果还没初始化) 如果你的本地项目还没有 Git 仓库,先进入你的项目目录,并初始化 Git:   cd /你的本地项目路径 git init 这样会在你的项目中创建一 ...

  9. HttpClient 进行soap请求

    当你在使用C#的HttpClient进行SOAP请求时,确保你的代码类似于以下示例: using System; using System.Net.Http; using System.Text; u ...

  10. 在Linux系统下验证万兆网络(10Gbps)的性能和配置情况,可以通过多种方法来实现

    在Linux系统下验证万兆网络(10Gbps)的性能和配置情况,可以通过多种方法来实现.以下是一些常用的步骤和工具: 1. 确认硬件支持 首先,确保您的计算机硬件支持万兆网络.这包括: 网卡:确认您的 ...