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)的更多相关文章

  1. 笔记11 在XML中声明切面(2)

    为通知传递参数 1.声明一个CompactDiscs接口.内部包含两个方法: show() 用于显示唱片的名字和艺术风格 playTrack(int number) 根据传入的磁道数播放相应磁道的音乐 ...

  2. Spring AOP 在XML中声明切面

    转载地址:http://www.jianshu.com/p/43a0bc21805f 在XML中将一个Java类配置成一个切面: AOP元素 用途 <aop:advisor> 定义AOP通 ...

  3. Spring 在XML中声明切面/AOP

    在Spring的AOP配置命名空间中,我们能够找到声明式切面选择.看以下: <aop:config> <!-- AOP定义開始 --> <aop:pointcut/> ...

  4. 获取在attr.xml中声明的主题样式

    在换肤时,先在attr.xml中定义Resource的属性名,再到stytle中,根据不同的主题,给属性赋值. 在布局文件中可直接以  android:background="?attr/a ...

  5. SpringMVC: web.xml中声明DispatcherServlet时一定要加入load-on-startup标签

    游历SpringMVC源代码后发现,在web.xml中注冊的ContextLoaderListener监听器不过初始化了一个根上下文,只完毕了组件扫描和与容器初始化相关的一些工作,并没有探測到详细每一 ...

  6. SpringMVC: web.xml中声明DispatcherServlet时一定要添加load-on-startup标签

    游历SpringMVC源码后发现,在web.xml中注册的ContextLoaderListener监听器只是初始化了一个根上下文,仅仅完成了组件扫描和与容器初始化相关的一些工作,并没有探测到具体每个 ...

  7. tornado 学习笔记10 Web应用中模板(Template)的工作流程分析

             第8,9节中,我们分析Tornado模板系统的语法.使用以及源代码中涉及到的相关类,而且对相关的源代码进行了分析.那么,在一个真正的Web应用程序中,模板到底是怎样使用?怎样被渲染? ...

  8. maven使用笔记--在父pom中声明过的jar可以被继承,使子项目不用写版本号由父pom控制

    将dependencies放到dependencyManagement中,如下: [html] view plaincopy <dependencyManagement> <depe ...

  9. AndroidManifest.xml中声明权限——各种permission含义摘录

    android.permission.EXPAND_STATUS_BAR 允许一个程序扩展收缩在状态栏,android开发网提示应该是一个类似Windows Mobile中的托盘程序 android. ...

随机推荐

  1. Vim 游戏 2048

    给大家介绍一款可以在Vim里面玩的游戏 vim2048. 界面如图: 操作非常简单,可以用 hjkl 或者 上下左右方向键移动 项目开源地址为: https://github.com/wsdjeg/v ...

  2. 前端面试题:JS中的let和var的区别

    最近很多前端的朋友去面试被问到let和var的区别,其实阮一峰老师的ES6中已经很详细介绍了let的用法和var的区别.我简单总结一下,以便各位以后面试中使用. ES6 新增了let命令,用来声明局部 ...

  3. Hadoop完全分布式安装教程

    一.软件版本 Hadoop版本号:hadoop-2.6.0.tar: VMWare版本号:VMware-workstation-full-11.0.0-2305329 Ubuntu版本号:ubuntu ...

  4. Ubuntu16.04建立本地更新源

    公司有多台Ubuntu机器,而且不能连接互联网,导致安装软件和更新都比较麻烦,需要建立一台本地更新源服务器. 1.安装apt-mirror工具 sudo apt-get install -y apt- ...

  5. 微信小程序组件学习中

    一.轮播图 wxml代码: <swiper indicator-dots="true" autoplay="true" duration="10 ...

  6. GIT入门笔记(20)- 使用eclipse 基于 git 开发过程梳理

    一.创建本地分支 1.下载/更新 本地 主干 如果本地还没有 本地主干,下载:git clone 如果本地已有了 本地主干,更新:git pull 工程右键菜单:team -> pull 2.基 ...

  7. 新概念英语(1-67)The weekend

    新概念英语(1-67)The weekend What are the Johnsons going to do at the weekend? A:Hello. Were you at the bu ...

  8. JavaScript中的 原型 property 构造函数 和实例对象之间的关系

    1 为什么要使用原型? /* * javascript当中 原型 prototype 对象 * * */ //首先引入 prototype的意义,为什么要使用这个对象 //先来写一个构造函数的面向对象 ...

  9. hive优化之——控制hive任务中的map数和reduce数

    一.    控制hive任务中的map数: 1.    通常情况下,作业会通过input的目录产生一个或者多个map任务.主要的决定因素有: input的文件总个数,input的文件大小,集群设置的文 ...

  10. 深度学习中Xavier初始化

    "Xavier"初始化方法是一种很有效的神经网络初始化方法,方法来源于2010年的一篇论文<Understanding the difficulty of training ...