笔记10 在XML中声明切面(1)
1.无注解的Audience
package XMLconcert;
public class Audience {
public void silenceCellPhones() {
System.out.println("Silencing cell phone");
}
public void takeSeats() {
System.out.println("Taking seats");
}
public void applause() {
System.out.println("CLAP CLAP CLAP");
}
public void demandRefund() {
System.out.println("Demanding a refund");
}
}
2.通过XML将无注解的Audience声明为切面
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:c="http://www.springframework.org/schema/c"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="audience" class="XMLconcert.Audience"></bean>
<bean class="XMLconcert.Classcial"></bean>
<aop:config>
<aop:aspect ref="audience">
<aop:before pointcut="execution(* XMLconcert.Performance.perform(..))" method="silenceCellPhones"/>
<aop:before pointcut="execution(* XMLconcert.Performance.perform(..))" method="takeSeats"/>
<aop:after-returning pointcut="execution(* XMLconcert.Performance.perform(..))" method="applause"/>
<aop:after-throwing pointcut="execution(* XMLconcert.Performance.perform(..))" method="demandRefund"/>
</aop:aspect>
</aop:config> </beans>
或者
<aop:config>
<aop:aspect ref="audience">
<aop:pointcut expression="execution(* XMLconcert.Performance.perform(..))" id="performance"/>
<aop:before pointcut-ref="performance" method="silenceCellPhones"/>
<aop:before pointcut-ref="performance" method="takeSeats"/>
<aop:after-returning pointcut-ref="performance" method="applause"/>
<aop:after-throwing pointcut-ref="performance" method="demandRefund"/>
</aop:aspect>
</aop:config>
或者
替换Audience中的四个方法
public void watchPerformance(ProceedingJoinPoint jp) {
try {
System.out.println("Silencing cell phone");
System.out.println("Taking seats");
jp.proceed();
System.out.println("CLAP CLAP CLAP");
} catch (Throwable e) {
System.out.println("Demanding a refund");
}
}
<aop:config>
<aop:aspect ref="audience">
<aop:pointcut expression="execution(* XMLconcert.Performance.perform(..))" id="performance"/>
<aop:around method="watchPerformance" pointcut-ref="performance"/>
</aop:aspect>
</aop:config>
3.结果

笔记10 在XML中声明切面(1)的更多相关文章
- 笔记11 在XML中声明切面(2)
为通知传递参数 1.声明一个CompactDiscs接口.内部包含两个方法: show() 用于显示唱片的名字和艺术风格 playTrack(int number) 根据传入的磁道数播放相应磁道的音乐 ...
- Spring AOP 在XML中声明切面
转载地址:http://www.jianshu.com/p/43a0bc21805f 在XML中将一个Java类配置成一个切面: AOP元素 用途 <aop:advisor> 定义AOP通 ...
- Spring 在XML中声明切面/AOP
在Spring的AOP配置命名空间中,我们能够找到声明式切面选择.看以下: <aop:config> <!-- AOP定义開始 --> <aop:pointcut/> ...
- 获取在attr.xml中声明的主题样式
在换肤时,先在attr.xml中定义Resource的属性名,再到stytle中,根据不同的主题,给属性赋值. 在布局文件中可直接以 android:background="?attr/a ...
- SpringMVC: web.xml中声明DispatcherServlet时一定要加入load-on-startup标签
游历SpringMVC源代码后发现,在web.xml中注冊的ContextLoaderListener监听器不过初始化了一个根上下文,只完毕了组件扫描和与容器初始化相关的一些工作,并没有探測到详细每一 ...
- SpringMVC: web.xml中声明DispatcherServlet时一定要添加load-on-startup标签
游历SpringMVC源码后发现,在web.xml中注册的ContextLoaderListener监听器只是初始化了一个根上下文,仅仅完成了组件扫描和与容器初始化相关的一些工作,并没有探测到具体每个 ...
- tornado 学习笔记10 Web应用中模板(Template)的工作流程分析
第8,9节中,我们分析Tornado模板系统的语法.使用以及源代码中涉及到的相关类,而且对相关的源代码进行了分析.那么,在一个真正的Web应用程序中,模板到底是怎样使用?怎样被渲染? ...
- maven使用笔记--在父pom中声明过的jar可以被继承,使子项目不用写版本号由父pom控制
将dependencies放到dependencyManagement中,如下: [html] view plaincopy <dependencyManagement> <depe ...
- AndroidManifest.xml中声明权限——各种permission含义摘录
android.permission.EXPAND_STATUS_BAR 允许一个程序扩展收缩在状态栏,android开发网提示应该是一个类似Windows Mobile中的托盘程序 android. ...
随机推荐
- LeetCode & Q268-Missing Number-Easy
Array Math Bit Manipulation Description: Given an array containing n distinct numbers taken from 0, ...
- Windows中添加自己的程序到开机启动中(添加服务,添加注册表)
在系统启动的时候启动自己想要启动的程序: 方法一:利用开机启动文件夹 将exe文件或exe文件的快捷方式复制到(启动)文件夹下 以win7为例:开始→所有程序→启动→鼠标右键打开 方法二:添加系统服务 ...
- CentOS 7 GUI图形界面安装
在此之前先获取root权限,进行以下命令: 1. 在命令行下输入下面的命令来安装Gnome包: yum groupinstall "GNOME Desktop" "Gra ...
- kubernetes入门(10)kubernetes单机安装后 - helloworld
前言 查看端口是否被监听了 ::netstat -tlp |grep 31002 我是用的yum install etcd kubernetes docker vim, 这样装的是1.5.2,不是最新 ...
- 阿里云API网关(1)服务网关的产品概述
网关指南: https://help.aliyun.com/document_detail/29487.html?spm=5176.doc48835.6.550.23Oqbl 网关控制台: https ...
- less初学手记
less语言学习手记 工具下载 在less学习中,我们都会需要随时编译我们的less文件,查看生成的css样式表是否正确,以及是否符合我们的要求.推荐一款编译软件供大家下载使用:koala,本软件支持 ...
- UVA850【简单模拟】
题目:解密句子.有一些被加密的句子已知一条模板翻译,判断是否可以解密,可以的话将所有句子解密. #include <stdio.h> #include<iostream> #i ...
- mysql 千万级数据查询效率实践,分析 mysql查询优化实践--本文只做了一部分,仅供参考
数据量, 1300万的表加上112万的表 注意: 本文只做了部分优化,并不全面,仅供参考, 欢迎指点. 请移步tim查看,因为写的时候在tim写的,粘贴过来截图有问题,就直接上链接了. https ...
- spark算子:partitionBy对数据进行分区
def partitionBy(partitioner: Partitioner): RDD[(K, V)] 该函数根据partitioner函数生成新的ShuffleRDD,将原RDD重新分区. s ...
- POJ-1995 Raising Modulo Numbers---快速幂模板
题目链接: https://vjudge.net/problem/POJ-1995 题目大意: 求一堆ab的和模上m 思路: 直接上模板 #include<iostream> #inclu ...