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. 如何判断自己的浏览器支持的是javascript的那个版本

    <script language="javascript"> var jsversion = 1.0; </script> <script langu ...

  2. Xshell批量导入IP地址

    我的xshell被覆盖了~~~结果原来的host没了,很郁闷要一个一个添加,网上找了很长时间在Xshell中批量添加IP的文章,结果都不行. 最后找到了https://blog.netsarang.c ...

  3. css模拟下拉菜单

    <!DOCTYPE html > <head>     <meta http-equiv="Content-Type" content="t ...

  4. Oracle 存储过程 延迟执行 DBMS_LOCK.SLEEP(60);

      --测试代码: declare -- Local variables here i integer; begin -- Test statements here dbms_output.put_l ...

  5. Where is virtualenvwrapper.sh after pip install?

      I'm trying to setup virtualenvwrapper on OSX, and all the instructions and tutorials I've found te ...

  6. ldap快速配置

    1.[yum lamp环境] yum  -y install httpd httpd-devel mysql mysql-server mysql-devel php php-mysql php-co ...

  7. HTML5 Canvas ( 文字横纵对齐 ) textAlign, textBaseLine

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  8. VisualSVN:允许修改svn提交日志(pre-revpro-change hook)

    有时候需要对之前版本提交的错误的日志信息进行修改或者进行补充描述: 1.在windows 7( 64位 )下使用TortoiseSVN客户端,选中代码目录,点击右键,选择<显示日志> 在出 ...

  9. 更新403 Forbidden

    用TidHTTP下载一个文件 http://192.168.1.1/files/新建文本文档.txt 报错,但是用浏览器打开正常 HTTP/1.1 403 Forbidden 最后不是程序的问题,把i ...

  10. AS3 - 数组元素乱序方法以及效率比较

    http://www.hangge.com/blog/cache/detail_453.html