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 ...
随机推荐
- H3C-L2TP
l2tp enable #启用l2tp domain system authentication ppp local # 本地认证 access-limit disable state active ...
- c++之函数值传递和引用传递解析----关键在于理解函数return的实现机制(内存分配)
函数调用过程解析 func里的a存储在调用fun函数时开辟的栈空间里,这块栈只在调用func时对func可用,调用结束后返回的a,其实是暂存在寄存器里的(一般情况下是eax),而返回到main里时,m ...
- MTK UART串口调试
一.UART初始化 1. kernel-3.18/drivers/misc/mediatek/uart/uart.c static int __init mtk_uart_init(void) { ; ...
- POJ1226(strstr)
Substrings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13348 Accepted: 4722 Descr ...
- @Autowired注解和启动自动扫描的三种方式(spring bean配置自动扫描功能的三种方式)
前言: @Autowired注解代码定义 @Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, Elemen ...
- su命令,sudo命令,visudo命令
一.命令su 语法 : su [-] username后面可以跟 ‘-‘ 也可以不跟,普通用户su不加username时就是切换到root用户,当然root用户同样可以su到普通用户. ‘-‘ 这个字 ...
- ubuntu下安装显卡驱动
前言 以下内容是个人学习之后的感悟,转载请注明出处~ 作者的显卡是GT 730,现以NVIDIA-Linux-x86-384.69为例. 1.打开终端,先删除旧的驱动: sudo ...
- java:calendar类及一些比较实用的utils(一)
在java编程中经常会用到时间日期的计算.比较.格式化等等操作,刚开始接触Calendar类时,还是在初学习期间,小小白一枚,看着这个好复杂,懒惰心理作祟也就没有怎么去学习,后来在项目中经常用到,索性 ...
- 怎么在Ubuntu下设置程序的快捷键
参考 http://jingyan.baidu.com/article/1e5468f97f9e75484861b773.html 我的系统是 64bit Ubuntu14.04 我设置了 gedit ...
- Lua 不是 C++
http://blog.codingnow.com/2008/08/lua_is_not_c_plus_plus.html 嗯,首先,此贴不是牢骚帖. 话题从最近私人的一点工作开始.应 dingdan ...