1.1、

    Aop,  aspect object programming  面向切面编程

                    功能: 让关注点代码与业务代码分离!

            关注点,

                  重复代码就叫做关注点;

            切面,

                  关注点形成的类,就叫切面(类)!

                  面向切面编程,就是指 对很多功能都有的重复的代码抽取,再在运行的时候往业务方法上动态植入“切面类代码”。

            切入点,

                  执行目标对象方法,动态植入切面代码。

                  可以通过切入点表达式,指定拦截哪些类的哪些方法; 给指定的类在运行的时候植入切面类代码。

代码示例如下:

UserDao  目标对象

package com.murong.aop;

/**
* 目标对象
*/
public class UserDao
{
public void save()
{
System.out.println("-----核心业务:保存!!!------");
}
}

Aop  切面类

package com.murong.aop;

/**
*切面类
*/
public class Aop
{
public void testPointCut(){ }
public void begin()
{
System.out.println("事务开启");
}//关注点代码 public void end()
{
System.out.println("事务结束");
}//关注点代码
}

ApplicationContext  配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd"
default-autowire="byType"> <bean id="userDao" class="com.murong.aop.UserDao"/> <bean id="aop" class="com.murong.aop.Aop"/> <aop:config>
<aop:aspect ref="aop">
<aop:before method="begin" pointcut="execution(* com.murong.aop.UserDao.*(..))"></aop:before>
<aop:after method="end" pointcut="execution(* com.murong.aop.UserDao.*(..))"></aop:after>
</aop:aspect>
</aop:config> </beans>

App  测试类

package com.murong.aop;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class App
{
private ApplicationContext ac = new ClassPathXmlApplicationContext("com/murong/aop/applicationContext");
@Test
public void test()
{
UserDao dao = (UserDao) ac.getBean("userDao");
dao.save();
}
}

结果:

设计模式(六) xml方式实现AOP的更多相关文章

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

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

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

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

  3. Spring3.0 入门进阶(三):基于XML方式的AOP使用

    AOP是一个比较通用的概念,主要关注的内容用一句话来说就是"如何使用一个对象代理另外一个对象",不同的框架会有不同的实现,Aspectj 是在编译期就绑定了代理对象与被代理对象的关 ...

  4. spring框架之AspectJ的XML方式完成AOP的开发

    1. 步骤一:创建JavaWEB项目,引入具体的开发的jar包 * 先引入Spring框架开发的基本开发包 * 再引入Spring框架的AOP的开发包 * spring的传统AOP的开发的包 * sp ...

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

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

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

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

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

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

  8. xml方式实现aop编程

    第一:引入jai文件 第二:引入aop名称空间 第三:配置aop

  9. spring----IOC注解方式以及AOP

    技术分析之Spring框架的IOC功能之注解的方式 Spring框架的IOC之注解方式的快速入门 1. 步骤一:导入注解开发所有需要的jar包 * 引入IOC容器必须的6个jar包 * 多引入一个:S ...

随机推荐

  1. Servlet Servlet是Java平台上的CGI技术

    Servlet Servlet是Java平台上的CGI技术.Servlet在服务器端运行,动态地生成Web页面.与传统的CGI和许多其它类似CGI的技术相比,Java Servlet具有更高的效率并更 ...

  2. reactjs中props和state最佳实践

    http://blog.csdn.net/dangnian/article/details/50998981

  3. Volley 的使用以及自定义Request

    Volley 的使用以及自定义Request 一.什么是 Volley 2013年Google I/O大会上推出了一个新的网络通信框架.Volley是Android平台上的网络通信库,能使网络通信更快 ...

  4. python中的json和pickle

    author:headsen chen date::2018-04-10  09:56:54 json模块和pickle模块: 这是用于序列化的两个模块: 概念介绍:json和pickle模块是将数据 ...

  5. 转载:Eslint 规则说明

    原文: http://blog.csdn.net/helpzp2008/article/details/51507428 ,//禁止使用alert confirm prompt ,//禁止使用数组构造 ...

  6. ZOJ 3331 Process the Tasks(双塔DP)

    Process the Tasks Time Limit: 1 Second      Memory Limit: 32768 KB There are two machines A and B. T ...

  7. java反射——字段

    大家都知道反射技术在Java里面时非常重要的一个技术点,因为Java好多框架的编写都是基于反射的,别的不多说,spring框架里面的IOC就是基于反射实现.那么什么是反射呢?JAVA反射机制是在运行状 ...

  8. Oracle Schema Objects——Tables——TableType

    Oracle Schema Objects Object Tables object type An Oracle object type is a user-defined type with a ...

  9. decode-encode --其他使用可能有问题

    SELECT id,DECODE(name,'password') FROM test UPDATE test SET `name`=ENCODE(`name`,'password')

  10. QQ视频直播架构及原理 流畅与低延迟之间做平衡 音画如何做同步?

    QQ视频直播架构及原理 - tianyu的专栏 - CSDN博客 https://blog.csdn.net/wishfly/article/details/53035342 作者:王宇(腾讯音视频高 ...