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的更多相关文章

  1. 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 ...

  2. Spring使用AspectJ开发AOP:基于XML

    基于XML的声明式 基于 XML 的声明式是指通过 Spring 配置文件的方式定义切面.切入点及声明通知,而所有的切面和通知都必须定义在 <aop:config> 元素中. 下面通过案例 ...

  3. spring-AOP动态代理,以及aspectJ的xml配置或注解配置方法,各个拦截器的使用顺序

    package com.itheima.aspect; public class MyAspect { public void check_Permissions(){ System.out.prin ...

  4. 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:Spring使用AspectJ开发AOP基于XML和基于Annotation

    AspectJ 是一个基于 Java 语言的 AOP 框架,它扩展了 Java 语言.Spring 2.0 以后,新增了对 AspectJ 方式的支持,新版本的 Spring 框架,建议使用 Aspe ...

  5. AspectJ AOP学习基础

    一.切入点表达式 1.execution:匹配方法的执行 格式:execution(修饰符 返回值类型 包.类.方法(参数) throw 异常) 1.1修饰符,表示方法的修饰符,一般省略. 1.2返回 ...

  6. Spring AOP + AspectJ Annotation Example---reference

    In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...

  7. AOP中的ASPECTJ

    一.准备 1.架包 2.配置文件 二.注解的形式 UserDao.java package cn.itcast.spring.aspectj.annocation; public class User ...

  8. 使用@AspectJ注解开发Spring AOP

    一.实体类: Role public class Role { private int id; private String roleName; private String note; @Overr ...

  9. Spring -- aop, 用Aspectj进行AOP开发

    1. 概要 添加类库:aspectjrt.jar和aspectjweaver.jar 添加aop schema. 定义xml元素:<aop:aspectj-autoproxy> 编写jav ...

随机推荐

  1. 【转】JBoss Web和 Tomcat的区别

    转载于:http://www.verydemo.com/demo_c202_i780.html JBoss Web和 Tomcat的区别 在Web2.0的浪潮中,各种页面技术和框架不断涌现,为服务器端 ...

  2. hadoop源码剖析--RawLocalFileSystem

    RawLocalFileSystem是hadoop中实现的本地文件系统,在该类中与文件元数据和目录相关的操作,都是通过适配方式适配到java.io.File的对应API来完成的,适配过程简单,代码清晰 ...

  3. C++之static类成员,static类成员函数

    0.static修饰类中成员,表示类的共享数据 1.static类成员 在C++primer里面说过,static类成员不像普通的类数据成员,static类数据成员独立于一切类对象处在.static类 ...

  4. Mysql数据库--语句整理/提升/进阶/高级使用技巧

    一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...

  5. Oracle数据库当前连接数、最大连接数的查询与设置

    在开发过程中Oracle数据库有时候连得上,有时候又连不上,提示如下异常“ORA-12519: TNS:no appropriate service handler found 解决”,可能是数据库上 ...

  6. OpenCV在Zedboard上的移植

    OpenCV编译 本文的前提是zynq交叉编译环境设置 下载opencv3.1.0源码,并解压 wget https://github.com/Itseez/opencv/archive/3.1.0. ...

  7. nohup command > myout.file 2>&1 &

    nohup command > myout.file 2>&1 &

  8. 使用libvirt技术监控虚拟机资源利用情况

    使用libvirt技术监控虚拟机资源利用情况 (一)计算资源与内存资源的监控 libvirt中提供virDomainGetInfo方法可以将一个domain的计算资源和内存资源的使用情况封装在一个结构 ...

  9. Python之线程与GIL

    前言            以下内容是个人学习之后的感悟,转载请注明出处~ 线程是什么 线程是程序中一个单一的顺序控制流程.进程内一个相对独立的.可调度的执行单元,是系统独立调度和分派CPU的 基本单 ...

  10. 超级简单的跨平台高性能音视频播放框架QtAv编译指南

    目录 一.了解QtAv 二.相关文章 三.下载QtAv源码 四.下载QtAv依赖库 五.设置环境变量 1.gcc设置方式 2.msvc(cl)设置方式 六.编译 七.测试 一.了解QtAv 这几天抱着 ...