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. 从PRISM开始学WPF(四)Prism-Module?

    从PRISM开始学WPF(一)WPF? 从PRISM开始学WPF(二)Prism? 从PRISM开始学WPF(三)Prism-Region? 从PRISM开始学WPF(四)Prism-Module? ...

  2. 18-TypeScript模板方法模式

    在有些情况下,一个功能在基础功能上是不会变的,算法的基本骨架也是确定的,但是在某些场景下算法的具体实现有些差异.应对这种问题,可以采用模板方法模式: abstract class Salary{ ab ...

  3. AngularJS1.X学习笔记8-自定义指令(上)

    AngulaJS的指令是一种非常强大的特性,一个ng-repeat就能让我们非常方便的展示一个数据列表,指令相当于是一个组件,为我们将一些东西封装起来了,提供了复用的可能性.个人认为自定义指令还是比较 ...

  4. Java 10 的 10 个新特性,将彻底改变你写代码的方式!

    Java 9才发布几个月,很多玩意都没整明白,现在Java 10又快要来了.. 这时候我真尼玛想说:线上用的JDK 7 甚至JDK 6,JDK 8 还没用熟,JDK 9 才发布不久不知道啥玩意,JDK ...

  5. CentOS7下安装python-pip

    一.检查是否已经安装 检查linux有没有安装python-pip包,直接执行:: yum install python-pip 二.安装 pip install 1.没有python-pip包就执行 ...

  6. spring6——AOP的编程术语

    面向切面编程作为一种编程思想,允许我们对程序的执行流程及执行结果动态的做出改变,以达到业务逻辑之间的分层管理或者是目标对象方法的增强,spring框架很好的实现了这种编程思想,让我们可以对主业务逻辑和 ...

  7. Python之面向对象四

    面向对象进阶 一.关于面向对象的两个内置函数 isinstance   判断类与对象的关系    isinstance(obj,cls)检查obj是否是类 cls 的对象,返回值是bool值 issu ...

  8. 记录项目中用的laypage分页代码

    最终才觉得,好记性不如烂笔头,毕竟已经不是刚毕业时候的巅峰了,精力有所下降,很多时候记不住东西. 参考url:http://www.layui.com/laypage/ 直接上代码了 <scri ...

  9. JQuery Layer的应用实例

    参考以上链接:https://blog.csdn.net/zlj_blog/article/details/24994799 sql面试题:https://www.cnblogs.com/qixuej ...

  10. django知识回顾

    一.web框架 1.web框架本质 众所周知,对于所有的web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端 1.浏览器(socket客户端) 2.发送IP和端 ...