achieve aop through xml
The main way to achive AOP is deploying a xml file。
Now a xml file is presented to be a explanation .
<?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:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<context:annotation-config />
<context:component-scan base-package="com.bjsxt"/>
<bean id="logInterceptor" class ="com.bjsxt.aop.LogInterceptor"></bean>
<aop:config>
<aop:pointcut
expression="execution(public * com.bjsxt.service..*.add(..))"
id="servicePointcut"/> <aop:aspect id="logAspect" ref="logInterceptor">
<aop:before method="before" pointcut-ref="servicePointcut" />
</aop:aspect>
</aop:config> </beans>
The tag <aop:config> declares that we will deploy a aop now.
While , I declare a "pointcut" at first. It is obvious that it's a globe pointcut and it works for every aspect behind it .
"expression="execution(public * com.bjsxt.service..*.add(..))" shows the pointcut represent all method like “add()” in the classes of the package named"com.bjsxt.service.."
the pointcut‘s id is “servicePointcut” in addition。
Next, a aspect is declared whose name is “logAspect” 。
(nobody care what name it has in this situation)。
pointcut-ref="servicePointcut" shows that it is a aspect for the pointcut named “servicePointcut”which we had created a moment ago.
Its ref = <span style="font-family: Arial, Helvetica, sans-serif;">"logInterceptor" ,so we can find a bean named logInterceptor to know what methods the aspect has。 And according to the sentence “<aop:before method</span>
<span style="font-family: Arial, Helvetica, sans-serif;">="before" " , I think we must do the method named "before" in "logIntercepor " as the type of" before method". It means the method woulb be done before pointcut.</span>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
<span style="font-family: Arial, Helvetica, sans-serif;">We can also complete the xml file in design mode。 It looks much more clear.</span>
<span style="font-family: Arial, Helvetica, sans-serif;">
</span>
achieve aop through xml的更多相关文章
- spring aop 使用xml方式的简单总结
spring aop的 xml的配置方式的简单实现: 1.编写自己的切面类:配置各个通知类型 /** * */ package com.lilin.maven.service.aop; import ...
- Spring的第三天AOP之xml版
Spring的第三天AOP之xml版 ssm框架 spring AOP介绍 AOP(Aspect Oriented Programming),面向切面编程.它出来的目的并不是去取代oop,而是对它的 ...
- spring中aop以xml配置方式
1 引jar包 springAOP\aopalliance.jar springAOP\aspectjrt.jar springAOP\aspectjweaver.jar springAOP\spri ...
- Spring中基于AOP的XML架构
以下内容引用自http://wiki.jikexueyuan.com/project/spring/aop-with-spring-framenwork/xml-schema-based-aop-wi ...
- Spring_IoC注解开发和AOP的XML开发(学习笔记2)
一:IoC注解开发 1,在applicationContext.xml中需要引入context约束 <beans xmlns="http://www.springframework.o ...
- Spring 中基于 AOP 的 XML架构
Spring 中基于 AOP 的 XML架构 为了使用 aop 命名空间标签,你需要导入 spring-aop j架构,如下所述: <?xml version="1.0" e ...
- [刘阳Java]_Spring AOP基于XML配置介绍_第9讲
基于注解配置的Spring AOP固然简单,但是这节我们会给大家介绍基于XML配置的AOP是如何应用的.为什么这么说了,因为后面我们还会介绍到Spring对Dao操作的事务管理(基于AOP的XML文件 ...
- Spring AOP基于xml配置实例
SpringAOP里的几个术语,什么切面,切点之类的,官方的说明太抽象.为了更好地理解记忆,这里几下我自己的通俗的理解. 切面:就是日记类,什么前置通知后置通知(这些都是所谓的Advice)的具体方法 ...
- spring中的aop的xml配置方式简单实例
aop,即面向切面编程,面向切面编程的目标就是分离关注点,比如:一个骑士只需要关注守护安全,或者远征,而骑士辉煌一生的事迹由谁来记录和歌颂呢,当然不会是自己了,这个完全可以由诗人去歌颂,比如当骑士出征 ...
随机推荐
- 利用Ihttpmodel实现网站缓存,解决Server.Transfer 直接输出HTML源代码的问题
今天在用.NET利用IHttpModel实现网站静态缓存的时候,不知道最后为什么用 Server.Transfer(html)的时候结果输出的是HTML的源代码. 贴上源代码 using System ...
- 11.ThinkPHP 3.1.2 连贯操作
==================================================== 一.常用连贯操作 1.where 帮助我们设置查询条件 2.order 对结果进行排序 $ar ...
- 为什么出现Wide character in print at a14.pl line 41
[root@wx03 ~]# cat a14.pl use Net::SMTP; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Headers; u ...
- 基于visual Studio2013解决C语言竞赛题之1029二元数组平均值
题目 解决代码及点评 /* 功能:求二维数组中每行元素的平均值,不许引入其它的数组 时间:16:21 2013/10/24 */ #include<stdio ...
- Swift - 动态添加删除TableView的单元格(以及内部元件)
在Swift开发中,我们有时需要动态的添加或删除列表的单元格. 比如我们做一个消息提醒页面,默认页面只显示两个单元格.当点击第二个单元格(时间标签)时,下面会再添加一个单元格放置日期选择控件(同时新增 ...
- 基于unity3d和leap motion的拼图游戏
近期用unity3d引擎做了一个拼图游戏,会分几次写完,以此作为总结. 本文基本查找了网上能查到的全部资料作为參考.也算是大家节省了时间. 眼下仅仅完毕了拼图部分,leap motion手势控制部分会 ...
- 注解在android中的使用
注解在android程序中的使用 何为注解: 在Java其中,注解又叫做"元数据",它为我们在源码中加入信息提供了一种形式化的方法.让我们能在以后的某个时间方便的使用这些数据.更确 ...
- unix ourhdr.h myerr.h
//在学UNIX环境高级编程时把下面两个头文件与源文件放在同一个文件下就可以正常编译了,我的是在ubuntu 12.04环境下,第一个程序编译和运行成功了,希望对大家有帮助(我已经根据网上的资料修改好 ...
- Lucene.Net 2.3.1开发介绍 —— 三、索引(三)
原文:Lucene.Net 2.3.1开发介绍 -- 三.索引(三) 3.Field配置所产生的效果 索引数据,简单的代码,只要两个方法就搞定了,而在索引过程中用到的一些类里最简单,作用也不小的就是F ...
- 向大家推荐个android的游戏引擎——cocos2d-x
最近发现单单用android自带的功能函数来编写游戏,往往有很大的局限性,即耗时长,调试繁琐,没有一定的框架.所以博主发现了游戏引擎这个好东西,游戏引擎所拥有的架构和功能函数,使得游戏的编写更加得心应 ...