1. 步骤一:创建JavaWEB项目,引入具体的开发的jar包
* 先引入Spring框架开发的基本开发包
* 再引入Spring框架的AOP的开发包
* spring的传统AOP的开发的包
* spring-aop-4.2.4.RELEASE.jar
* com.springsource.org.aopalliance-1.0.0.jar * aspectJ的开发包
* com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
* spring-aspects-4.2.4.RELEASE.jar 2. 步骤二:创建Spring的配置文件,引入具体的AOP的schema约束
  * spring-framework-3.2.0.RELEASE\docs\spring-framework-reference\html\xsd-config.html,在这个网页中找到40.2.7 the aop schema,然后将下面标签中的内容复制粘贴单applicationContext.xml。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> 3. 步骤三:创建包结构,编写具体的接口和实现类
* com.huida.demo2
* CustomerDao -- 接口
package com.huida.demo3;

public interface CustomerDao {

    public void save();
public void update();
}
        * CustomerDaoImpl       -- 实现类
package com.huida.demo3;

public class CustomerDaoImpl implements CustomerDao{

    @Override
public void save() {
System.out.println("添加客户");
}
@Override
public void update() {
System.out.println("更新客户");
}
}
4. 步骤四:将目标类配置到Spring中
<bean id="customerDao" class="com.huida.demo3.CustomerDaoImpl"/> 5. 步骤五:定义切面类
public class MyAspectXml {
// 定义通知
public void log(){
System.out.println("记录日志...");
}
} 6. 步骤六:在配置文件中定义切面类
<bean id="myAspectXml" class="com.huida.demo3.MyAspectXml"/> 7. 步骤七:在配置文件中完成aop的配置
<aop:config>
<!-- 引入切面类 -->
<aop:aspect ref="myAspectXml">
<!-- 定义通知类型:切面类的方法和切入点的表达式 -->
<aop:before method="log" pointcut="execution(public * com.huida.demo3.CustomerDaoImpl.save(..))"/>
</aop:aspect>
</aop:config> 8. 完成测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class Demo3 {
@Resource(name="customerDao")
private CustomerDao customerDao;
@Test
public void run1(){
customerDao.save();
customerDao.update();
customerDao.delete();
}
}
9.单元测试run1(),执行结果为:
 

spring框架之AspectJ的XML方式完成AOP的开发的更多相关文章

  1. AspectJ的XML方式完成AOP的开发之切入点的表达式

    1. 再配置切入点的时候,需要定义表达式,重点的格式如下:execution(public * *(..)),具体展开如下: * 切入点表达式的格式如下: * execution([修饰符] 返回值类 ...

  2. 基于AspectJ的XML方式进行AOP开发

    -------------------siwuxie095                                 基于 AspectJ 的 XML 方式进行 AOP 开发         1 ...

  3. spring AOP (使用AspectJ的xml方式 的aop实现) (7)

    目录 一.定义计算器接口跟实现类 二.定义两个切面,日志切面和验证切面 三.在xml中配置切面 四.测试类 一.定义计算器接口跟实现类 public interface ArithmeticCalcu ...

  4. Spring框架学习08——自动代理方式实现AOP

    在传统的基于代理类的AOP实现中,每个代理都是通过ProxyFactoryBean织入切面代理,在实际开发中,非常多的Bean每个都配置ProxyFactoryBean开发维护量巨大.解决方案:自动创 ...

  5. AspectJ的XML方式完成AOP的开发之AOP的通知类型

    1. 前置通知 * 在目标类的方法执行之前执行. * 配置文件信息:<aop:after method="before" pointcut-ref="myPoint ...

  6. 【AOP】操作相关术语---【Spring】的【AOP】操作(基于aspectj的xml方式)

    [AOP]操作相关术语 Joinpoint(连接点):类里面哪些方法可以被增强,这些方法称为连接点. Pointcut(切入点):在类里面可以有很多的方法被增强,比如实际操作中,只是增强了类里面add ...

  7. Spring系列之aAOP AOP是什么?+xml方式实现aop+注解方式实现aop

    Spring系列之aop aop是什么?+xml方式实现aop+注解方式实现aop 什么是AOP? AOP为Aspect Oriented Programming 的缩写,意识为面向切面的编程,是通过 ...

  8. spring与hibernate注解及XML方式集成

    spring与hibernate注解及XML方式集成 Hibernate Xml方式 该种方式需要在sessionFactory中引入对应的hbm.xml文件,样例如下: <!-- spring ...

  9. Spring 的 Bean 管理(XML 方式)

    Spring 的 Bean 管理(XML 方式) 1. 三种实例化 Bean 的方式 使用类构造器实例化(默认无参数) 使用静态工厂方法实例化(简单工厂模式) 使用实例工厂方法实例化(工厂方法模式) ...

随机推荐

  1. ExtJS模板与菜单的使用案例-床位卡

    ExtJS的模板的使用: 项目中场景基本就是表格模型: TPL:自己编写模板 store:数据源 UI组件: tbar,rbr,bbar实现工具栏 PageBar与StatusBar:可以针对TPL的 ...

  2. RAID5---块,条带,校验,旋转,同步/异

    冗余(奇偶校验)块:RAID5中在同一个条带中用一个块来存放冗余信息,冗余信息示其他块的"异或"值,这样在同一条带中就只有(n-1)个块是实际的数据,所以RAID5中阵列容量是(n ...

  3. SQL Server 2012 OFFSET/FETCH NEXT分页示例

    原文:http://beyondrelational.com/modules/29/presentations/483/scripts/12983/sql-server-2012-server-sid ...

  4. 暴搜 - Codeforces Round #327 (Div. 2) E. Three States

    E. Three States Problem's Link Mean: 在一个N*M的方格内,有五种字符:'1','2','3','.','#'. 现在要你在'.'的地方修路,使得至少存在一个块'1 ...

  5. 很详细的curl命令使用大全

    可以看作命令行浏览器 1.开启gzip请求 curl -I http://www.sina.com.cn/ -H Accept-Encoding:gzip,defalte 2.监控网页的响应时间 cu ...

  6. 75. ID重新走过,备份表

    select * into ML_QuoteApply_InPro_bak20150629 from ML_QuoteApply_InPro truncate table ML_QuoteApply_ ...

  7. docker容器中搭建kafka集群环境

    Kafka集群管理.状态保存是通过zookeeper实现,所以先要搭建zookeeper集群 zookeeper集群搭建 一.软件环境: zookeeper集群需要超过半数的的node存活才能对外服务 ...

  8. 关于Nginx的负载均衡

    一.关于Nginx的负载均衡 在服务器集群中,Nginx起到一个代理服务器的角色(即反向代理),为了避免单独一个服务器压力过大,将来自用户的请求转发给不同的服务器.详情请查看我的另一篇博客. 二.Ng ...

  9. PHP依赖注入(DI)和控制反转(IoC)详解

    这篇文章主要介绍了PHP依赖注入(DI)和控制反转(IoC)的相关资料,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 首先依赖注入和控制反转说的是同一个东西,是一种设计模式,这种设计模式用来减少程 ...

  10. Swagger从入门到精通

    https://legacy.gitbook.com/book/huangwenchao/swagger/details 如何编写基于OpenAPI规范的API文档 [TOC] 前言 编写目的 本文介 ...