如今比較流行了aop技术之中的一个========标签

实现步骤:

一,导入aop标签

方法,打开aop包。里面就有。

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">这个里面就有

然后依据选择spring的版本号。

在配置文件里配置

例如以下:

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:aop="http://www.springframework.org/schema/aop"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

这样就导入了aop标签

二,配置切点和通知

<aop:config>
<aop:aspect ref="myadvior"><!-- 须要导入作为切面的类-->
<aop:pointcut expression="execution(* cn..Person.*(..))" id="cut"/>
<aop:before method="test1" pointcut-ref="cut"/> <!-- 这是通知,拦截切点位置。也就是拦截时 须要做的事情 -->
<aop:aftermethod="test1" pointcut-ref="cut"/> <!-- 拦截核心之后运行的动作,所有写在test1方法里面了 -->
<!-- <aop:before method="test1" pointcut="execution(* cn..Person.*(..))"/> 这样也是能够的,就不用切点了,直接写在这里面 -->
</aop:aspect>
</aop:config>

里面的配置通知类型非常多

三。被代理类以及自己主动注解类

<span style="font-size:18px;"><!-- 须要的三元素 (被代理类, 自己主动代理类,切面)採用标签。切面和之前的有点不同。仅仅是一个简单的pojo导入 -->
<bean id="person" class="cn.aop.aspectj3.Person"></bean></span>
<span style="font-size:18px;"> <!-- 注解自己主动标签,自己主动去查找带有注解的类和方法 -->
<span style="white-space:pre"> </span> <aop:aspectj-autoproxy></aop:aspectj-autoproxy>
</span>

四。导入我们作为切面的类

<bean class="cn.aop.aspectj3.MyAdvisor" id="myadvior"/><!--当做切面的pojo 注入 -->

配置文件已经完毕。

五,被导入的作为切面的类

public class MyAdvisor {

		public void test1(){
System.out.println("这是test...");
}
}

非常普通的一类。方法名在配置切面里面,通知的时间也完毕了。。这里就能够实现想要完毕的动作了。

标签相当于之前的,有非常大的优化,如在核心模块全然不知道是都做了拦截,进一步实现了解耦。

=========================这里已经介绍完====================

源码以及測试

1,配置文件

<?

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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> <!-- 须要的三元素 (被代理类。 自己主动代理类,切面)採用标签,切面和之前的有点不同,仅仅是一个简单的pojo导入 -->
<bean id="person" class="cn.aop.aspectj3.Person"></bean> <!-- 自己主动代理注解
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"></bean>
-->
<!-- 注解自己主动标签,自己主动去查找带有注解的类和方法 -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy> <aop:config>
<aop:aspect ref="myadvior">
<aop:pointcut expression="execution(* cn..Person.*(..))" id="cut"/>
<aop:before method="test1" pointcut-ref="cut"/> <!-- 这是通知,拦截切点位置。也就是拦截时 须要做的事情 -->
<aop:aftermethod="test1" pointcut-ref="cut"/> <!-- 拦截核心之后运行的动作。所有写在test1方法里面了 -->
<!-- <aop:before method="test1" pointcut="execution(* cn..Person.*(..))"/> 这样也是能够的。就不用切点了,直接写在这里面 -->
</aop:aspect>
</aop:config> <bean class="cn.aop.aspectj3.MyAdvisor" id="myadvior"/><!--当做切面的pojo 注入 -->
</beans>

2,  作为切面的类

package cn.aop.aspectj3;

public class MyAdvisor {

		public void test1(){
System.out.println("这是test...");
}
}

3,被代理的对象

package cn.aop.aspectj3;

public class Person {

	public void say(){
System.out.println("...这是say..");
} public void run(){
System.out.println("这是person中的 run方法");
} }

4,測试

@Test
public void Test2(){
ApplicationContext context =new ClassPathXmlApplicationContext("cn/aop/aspectj3/aspectj3.xml");
Person p =context.getBean(Person.class);
p.run();
p.say();
}

javaEE之------ApectJ的切面技术===标签的更多相关文章

  1. [转载]JavaEE学习篇之——JQuery技术详解

    原文链接:http://blog.csdn.net/jiangwei0910410003/article/details/32102187 1.简介2.工具3.jQuery对象 1.DOM对象转化成j ...

  2. [JavaEE] 深入理解Struts2的ognl标签

    OGNL是Object-Graph Navigation Language的缩写,全称为对象图导航语言,是一种功能强大的表达式语言,它通过简单一致的语法,可以任意存取对象的属性或者调用对象的方法,能够 ...

  3. java的JSP技术

    java的JSP技术 [toc] 1.JSP简介 Jsp技术是用来开发java web的页面显示的,所有MVC模型里面的视图层,所以视图层的开发 jsp不是编程语言,三个英文是java server ...

  4. 面向切面编程AOP

    本文的主要内容(AOP): 1.AOP面向切面编程的相关概念(思想.原理.相关术语) 2.AOP编程底层实现机制(动态代理机制:JDK代理.Cglib代理) 3.Spring的传统AOP编程的案例(计 ...

  5. Servlet,jsp,JSP技术 ,JSP编程

     一.Servlet 思考 1 浏览器可以直接打开JAVA/class文件吗? 不可以 2浏览器可以打开HTML.JS 文件吗? 可以 3 JAVA程序可以生成HTML文件吗?可以的,用IO流. 4 ...

  6. 12、Jsp加强/自定义标签/JavaBean

    1 Jsp加强回顾 Jsp加强 1)Jsp的9大内置对象 request       HttpServletRequet response     HttpServletResponse config ...

  7. JSP技术基础(动态网页基础)

    前言:如果说html为静态网页基础,那么jsp就是动态网页基础,两者的区别就是jsp在html的前面多加了几行而已.当然,jsp里面对java的支持度更高.要明白,js只是嵌入在客户端的小程序小脚本而 ...

  8. 学习日常笔记<day14>自定义标签

    1自定义标签 1.1第一个自定义标签开发步骤 1)编写一个普通的java类,继承SimpleTagSupport类,叫标签处理器类 /** * 标签处理器类 * @author APPle * 1)继 ...

  9. javaEE之------Spring-----》 AspectJ注解

    前面介绍了下Spring中的切面技术.如今说下採用注解的方式进行切面 首先肯定和之前的一样.须要一个自己主动代理的注解类 AnnotationAwareAspectJAutoProxyCreator ...

随机推荐

  1. python之str (字符型)

    用途: 存储少量的数据,+ *int 切片, 其他操作方法 切片还是对其进行任何操作,获取的内容全部是strl类型 存储数据单一 格式: 在python中用引号引起来的就是字符串 '今天吃了没?' 1 ...

  2. vue 点击按钮弹窗,点击关闭按钮关闭弹窗。

    <div @click="btnfc()">点击弹窗按钮</div> <div v-show="show"> <div ...

  3. 【2018 CCPC网络赛】1009 - 树

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6446 题目给出的数据为一棵树,dfs扫描每条边,假设去掉某条边,则左边 x 个点,右边 n-x 个点, ...

  4. NOI2018_Day1_T1_归程

    题目描述 本题的故事发生在魔力之都,在这里我们将为你介绍一些必要的设定. 魔力之都可以抽象成一个 n 个节点.m 条边的无向连通图(节点的编号从 1 至 n). 我们依次用 l,a 描述一条边的长度. ...

  5. 快速安装zabbix

    环境:CentOS 7.x 数据库mysql已事先安装 1.配置epel源 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/r ...

  6. 文本三剑客之awk

    awk和流编辑器sed在工作原理和用法上有很多类似之处,它们都是检查输入数据中的行是否匹配指定的模式,如果匹配成功就对匹配的行执行相应的操作,重复这个过程直到所有的输入数据都被处理完,因此awk和se ...

  7. Python中的数据类型常见方法

    list() 方法 1.cmp(list1, list2):#比较两个列表的元素 2.len(list):#列表元素个数 3.max(list):#返回列表元素最大值 4.min(list):#返回列 ...

  8. zoj 1295 Reverse Text

    Reverse Text Time Limit: 2 Seconds      Memory Limit: 65536 KB In most languages, text is written fr ...

  9. BZOJ4553 - [TJOI2016]序列

    Portal Description 给出一个\(n(n\leq10^5)\)个数的数列\(\{a_n\}\)和\(m(m\leq10^5)\)个形如\((x,y)\)的变化,表示\(a_x\)可以变 ...

  10. HDU1423 最长公共上升子序列LCIS

    Problem Description This is a problem from ZOJ 2432.To make it easyer,you just need output the lengt ...