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 ...
随机推荐
- World Finals 2017 (水题题解)
看大佬做2017-WF,我这种菜鸡,只能刷刷水题,勉强维持生活. 赛后补补水题. 题目pdf链接,中文的,tls翻译的,链接在这里 个人喜欢在vjudge上面刷题. E Need for Speed ...
- OpenResty创造者
OpenResty 是一个开源的 Web 平台,用于开发高性能和高动态的 Web 网关或者 Web 应用.OpenResty 最早是为了支持全网搜索引擎周边的相关搜索的 API 接口,后来我们基于 N ...
- AtCoder Grand Contest 007 E:Shik and Travel
题目传送门:https://agc007.contest.atcoder.jp/tasks/agc007_e 题目翻译 现在有一个二叉树,除了叶子每个结点都有两个儿子.这个二叉树一共有\(m\)个叶子 ...
- bzoj 2655 calc —— 拉格朗日插值
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2655 先设 f[i][j] 表示长度为 i 的序列,范围是 1~j 的答案: 则 f[i][ ...
- Flutter实战视频-移动电商-13.首页_广告Banner组件制作
13.首页_广告Banner组件制作 主要是做这个小广告条. 其实就是读取一个图片做一个widget放到这里 使用stlessW快速生成 定义一个变量存放图片的url地址: 这样我们的广告条就写完了 ...
- dataTables使用ajax请求显示数据
dataTables是一种很好用前端表格显示库.当加载大量数据时,可以用Ajax 获取数据来提高效率,增速网页加载速率.下面以一个例子作示范. 首先,需要下载jQuery以及dataTables库.这 ...
- jquery table表格 获取选中的某一行和某一列的值
table class="table table-hover" id="test123"> <tr> <th width="4 ...
- hihocoder #1608 : Jerry的奶酪(状压DP)
传送门 题意 分析 设dp[i][j]为在i状态下当前在第j个奶酪的最小费用 转移方程:dp[(1<<k)|i][k]=dp[i][j]+d[j][k] 预处理出每个奶酪之间的距离,加入起 ...
- 如何在普通 UIViewController 中使用 UITableView
本系列文章 <Swift on iOS 学习笔记> 将以不定长度.不定内容.不定形式的方式对外发布,主要记录一些 “可重用” 的知识,感谢你的阅读. 在继承自 UIViewControll ...
- spark sql 的metastore 对接 postgresql
本教程记录 spark 1.3.1 版本的thriftserver 的metastore 对接 postgresql postgresql 的编译,参考:http://www.cnblogs.com/ ...