aspectj xml
1.接口和类

1.1 ISomeService 接口
public interface ISomeService {
public void doSome();
public void dade();
}
1.2 SomeService类
public class SomeService implements ISomeService {
//核心业务
public void doSome(){
System.out.println("我们都要找到Java开发工作,薪资6,7,8,9,10K");
}
public void dade() {
//异常
//int sun=5/0;
System.out.println("++++++++++++++de+++++++++++++");
}
}
1.3 MyAspect 类
public class MyAspect {
//前置增强
public void before(){
System.out.println("=====before========");
}
//后置增强
public void afterReturing(){
System.out.println("=====after========");
}
//后置增强 目标方法的返回值
public void afterReturing(String result){
System.out.println("=====后置通知方法 result========"+result);
}
//环绕通知
public Object around(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("目标方法执行前执行");
Object result = pjp.proceed();
System.out.println("目标方法执行后执行");
String temp=null;
if (result!=null) {
temp = (String) result;
temp=temp.toUpperCase();
}
return temp;
}
//异常通知
public void afterThrowing(){
System.out.println("异常通知");
}
//异常通知
public void afterThrowing(Exception ex){
System.out.println("异常通知 ex="+ex.getMessage());
}
//最终通知
public void after(){
System.out.println("最终通知");
}
}
2.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
">
<!--.目标对象-->
<bean id="someService" class="cn.bdqn.spring18.SomeService"></bean> <!--.增强类-->
<bean id="aspect" class="cn.bdqn.spring18.MyAspect"></bean> <!--aop-->
<aop:config>
<!--设置一个切点-->
<aop:pointcut id="mycut" expression="execution(* *..spring18.*.*(..))"></aop:pointcut>
<aop:aspect ref="aspect">
<aop:before method="before" pointcut-ref="mycut"></aop:before>
<aop:after-returning method="afterReturing" pointcut-ref="mycut"></aop:after-returning>
<aop:after-returning method="afterReturing(java.lang.String)" returning="result" pointcut-ref="mycut"></aop:after-returning>
<aop:around method="around" pointcut-ref="mycut"></aop:around>
<aop:after-throwing method="afterThrowing" pointcut-ref="mycut"></aop:after-throwing>
<aop:after-throwing method="afterThrowing(java.lang.Exception)" throwing="ex" pointcut-ref="mycut"></aop:after-throwing>
<aop:after method="after" pointcut-ref="mycut"></aop:after>
</aop:aspect>
</aop:config>
</beans>
3.测试类
//aspectj xml
@Test
public void test20(){
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContextspring16.xml");
ISomeService service = (ISomeService) ctx.getBean("someService");
service.doSome();
service.dade();
}
aspectj xml的更多相关文章
- Spring AOP + AspectJ in XML configuration example
For those don't like annotation or using JDK 1.4, you can use AspectJ in XML based instead. Review l ...
- Spring使用AspectJ开发AOP:基于XML
基于XML的声明式 基于 XML 的声明式是指通过 Spring 配置文件的方式定义切面.切入点及声明通知,而所有的切面和通知都必须定义在 <aop:config> 元素中. 下面通过案例 ...
- spring-AOP动态代理,以及aspectJ的xml配置或注解配置方法,各个拦截器的使用顺序
package com.itheima.aspect; public class MyAspect { public void check_Permissions(){ System.out.prin ...
- 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:Spring使用AspectJ开发AOP基于XML和基于Annotation
AspectJ 是一个基于 Java 语言的 AOP 框架,它扩展了 Java 语言.Spring 2.0 以后,新增了对 AspectJ 方式的支持,新版本的 Spring 框架,建议使用 Aspe ...
- AspectJ AOP学习基础
一.切入点表达式 1.execution:匹配方法的执行 格式:execution(修饰符 返回值类型 包.类.方法(参数) throw 异常) 1.1修饰符,表示方法的修饰符,一般省略. 1.2返回 ...
- Spring AOP + AspectJ Annotation Example---reference
In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...
- AOP中的ASPECTJ
一.准备 1.架包 2.配置文件 二.注解的形式 UserDao.java package cn.itcast.spring.aspectj.annocation; public class User ...
- 使用@AspectJ注解开发Spring AOP
一.实体类: Role public class Role { private int id; private String roleName; private String note; @Overr ...
- Spring -- aop, 用Aspectj进行AOP开发
1. 概要 添加类库:aspectjrt.jar和aspectjweaver.jar 添加aop schema. 定义xml元素:<aop:aspectj-autoproxy> 编写jav ...
随机推荐
- <编程>比较两种素数表生成算法+计算程序运行时间+通过CMD重定向测试程序
最近学习加密算法,需要生成素数表,一开始使用简单的循环,从2开始判断.代码如下: #include<iostream> #include<cstdio> #include< ...
- 转C++的一点点
为什么突然放些这么水的东西?我还是个C++小萌新,XD [一 litTLE经验值] 1. 注意 C++里 自带pow(x,y) 使用是没问题,尤其是pow(x,0.333333)这种时候很有用.但是 ...
- html锚点实现的方法
1 通过id <a href="#div1"> 通过id获取锚点</a> <div style=" height:200px; width: ...
- bzoj4589
fwt 原理并不知道 nim游戏石子异或和=0后手赢 那么也就是求a[1]^a[2]^...^a[n]=0的方案数 这个和bzoj3992一样可以dp dp[i][j]表示前i个数异或和为j的方案数 ...
- A - Toy Cars
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Little ...
- codevs-2235
2235 机票打折 题目描述 Description .输入机票原价(3到4位的正整数,单位:元),再输入机票打折率(小数点后最多一位数字).编程计算打折后机票的实际价格(单位:元.计算结果要将个位数 ...
- Numpy学习笔记<1>
1 numpy的ndarray:一种多维数组 a:创建ndarry 注意:np.array会尝试为新建的数组一个合适的数据类型 保存在dtype中 b:嵌套序列转换为一个多维数组 c:输出数据类型 ...
- shell脚本函数与数组
前言 之前写过一篇关于shell脚本流程控制总结,这次继续写关于shell脚本的问题.本篇文章主要包含shell脚本中的函数以及数组的用法介绍.同时也涵盖了一些字符串处理以及shell脚本比较使用的小 ...
- python 内置函数的补充 isinstance,issubclass, hasattr ,getattr, setattr, delattr,str,del 用法,以及元类
isinstance 是 python中的内置函数 , isinstance()用来判断一个函数是不是一个类型 issubclass 是python 中的内置函数, 用来一个类A是不是另外一个 ...
- 获取DataGridView上选中的一行并转换为一个DataRow类型
ataGridViewRow gridrow = dataGridView1.SelectedRows[0]; DataRowView row_view = (DataRowView)gridrow. ...