spring框架之AspectJ的XML方式完成AOP的开发
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的开发的更多相关文章
- AspectJ的XML方式完成AOP的开发之切入点的表达式
1. 再配置切入点的时候,需要定义表达式,重点的格式如下:execution(public * *(..)),具体展开如下: * 切入点表达式的格式如下: * execution([修饰符] 返回值类 ...
- 基于AspectJ的XML方式进行AOP开发
-------------------siwuxie095 基于 AspectJ 的 XML 方式进行 AOP 开发 1 ...
- spring AOP (使用AspectJ的xml方式 的aop实现) (7)
目录 一.定义计算器接口跟实现类 二.定义两个切面,日志切面和验证切面 三.在xml中配置切面 四.测试类 一.定义计算器接口跟实现类 public interface ArithmeticCalcu ...
- Spring框架学习08——自动代理方式实现AOP
在传统的基于代理类的AOP实现中,每个代理都是通过ProxyFactoryBean织入切面代理,在实际开发中,非常多的Bean每个都配置ProxyFactoryBean开发维护量巨大.解决方案:自动创 ...
- AspectJ的XML方式完成AOP的开发之AOP的通知类型
1. 前置通知 * 在目标类的方法执行之前执行. * 配置文件信息:<aop:after method="before" pointcut-ref="myPoint ...
- 【AOP】操作相关术语---【Spring】的【AOP】操作(基于aspectj的xml方式)
[AOP]操作相关术语 Joinpoint(连接点):类里面哪些方法可以被增强,这些方法称为连接点. Pointcut(切入点):在类里面可以有很多的方法被增强,比如实际操作中,只是增强了类里面add ...
- Spring系列之aAOP AOP是什么?+xml方式实现aop+注解方式实现aop
Spring系列之aop aop是什么?+xml方式实现aop+注解方式实现aop 什么是AOP? AOP为Aspect Oriented Programming 的缩写,意识为面向切面的编程,是通过 ...
- spring与hibernate注解及XML方式集成
spring与hibernate注解及XML方式集成 Hibernate Xml方式 该种方式需要在sessionFactory中引入对应的hbm.xml文件,样例如下: <!-- spring ...
- Spring 的 Bean 管理(XML 方式)
Spring 的 Bean 管理(XML 方式) 1. 三种实例化 Bean 的方式 使用类构造器实例化(默认无参数) 使用静态工厂方法实例化(简单工厂模式) 使用实例工厂方法实例化(工厂方法模式) ...
随机推荐
- iOS Xcode 调试技巧
一 NSLog调试 官方文档:Logs an error message to the Apple System Log facility. 即NSLog不是作为普通的debug log的,而是err ...
- WARN hdfs.DFSClient: Caught exception java.lang.InterruptedException
Hadoop 2.7.4 The reason is this: originally, DataStreamer::closeResponder always prints a warning ab ...
- 建造者模式(Builder)
Separate the construction of a complex object form its representation so that the same construction ...
- 开源推荐系统Librec中recommender模块算法了解——cf模块
1. k近邻(k-NearestNeighbor)算法介绍及在推荐系统中的应用 https://zhuanlan.zhihu.com/p/25994179 k近邻(k-NearestNeig ...
- Python Twisted系列教程1:Twisted理论基础
作者:dave@http://krondo.com/in-which-we-begin-at-the-beginning/ 译者:杨晓伟(采用意译) 前言: 最近有人在Twisted邮件列表中提出诸 ...
- selenium+python自动化87-Chrome浏览器静默模式启动(headless)
前言 selenium+phantomjs可以打开无界面的浏览器,实现静默模式启动浏览器完成自动化测试,这个模式是极好的,不需要占用电脑的屏幕. 但是呢,phantomjs这个坑还是比较多的,并且遇到 ...
- selenium+python自动化86-Chrome正在受到自动软件的控制
出现问题 1.用selenium启动浏览器出现'Chrome正在受到自动软件的控制' 2.如果不想看到这种讨厌的提示语,启动浏览器时候加个配置就行了 disable-infobars 1.在浏览器配置 ...
- uva-639-枚举
题意: 象棋里的車可以吃横竖的車,题目加了一个墙,用于阻断攻击,问4x4的棋盘最多可以放多少只車, 思路:枚举每一个点,2^16次方种情况 #include<stdio.h> #inclu ...
- 文件查找find命令
find命令总结: 常用选项: -name 查找/etc目录下以conf结尾的文件 find /etc -name '*conf' -iname 查找当前目录下文件名为aa的文件,不区分大小写 fin ...
- Java System.getProperty("java.io.tmpdir") 获取系统临时目录
System.getProperty("java.io.tmpdir") 是获取操作系统的缓存临时目录 在windows7中的目录是: C:\Users\登录用户~1\AppDat ...