zoukankan      html  css  js  c++  java
  • SPRING IN ACTION 第4版笔记-第四章ASPECT-ORIENTED SPRING-009-带参数的ADVICE2 配置文件为XML

    一、

    1.配置文件为xml时则切面类不用写aop的anotation

     1 package com.springinaction.springidol;
     2 
     3 public class Magician implements MindReader {
     4   private String thoughts;
     5 
     6   public void interceptThoughts(String thoughts) {
     7     System.out.println("Intercepting volunteer's thoughts");
     8     this.thoughts = thoughts;
     9   }
    10 
    11   public String getThoughts() {
    12     return thoughts;
    13   }
    14 }

    2.

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="http://www.springframework.org/schema/beans"
     3  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4  xmlns:aop="http://www.springframework.org/schema/aop"
     5  xsi:schemaLocation="http://www.springframework.org/schema/beans 
     6      http://www.springframework.org/schema/beans/spring-beans.xsd
     7      http://www.springframework.org/schema/aop
     8      http://www.springframework.org/schema/aop/spring-aop.xsd">
     9 
    10   <bean id="volunteer" 
    11       class="com.springinaction.springidol.Volunteer" />
    12   <bean id="magician" 
    13       class="com.springinaction.springidol.Magician" />
    14   
    15 <!--<start id="mindreading_aspect"/>--> 
    16   <aop:config>
    17     <aop:aspect ref="magician">
    18       <aop:pointcut id="thinking" 
    19         expression="execution(* 
    20         com.springinaction.springidol.Thinker.thinkOfSomething(String)) 
    21              and args(thoughts)" />
    22           
    23       <aop:before 
    24           pointcut-ref="thinking"
    25           method="interceptThoughts" 
    26           arg-names="thoughts" />
    27     </aop:aspect>
    28   </aop:config>
    29 <!--<end id="mindreading_aspect"/>-->
    30 
    31 </beans>
  • 相关阅读:
    maven学习(四)maven的生命周期
    maven学习(六)依赖、聚合、继承
    Koa2学习(三)GET请求
    Koa2学习(二)async/await
    Koa2学习(一)环境搭建
    实现一个简易的express中间件
    js生成页面水印
    使用 dva + antd 快速开发react应用
    使用ab 进行并发压力测试
    python3 使用http.server模块 搭建一个简易的http服务器
  • 原文地址:https://www.cnblogs.com/shamgod/p/5240084.html
Copyright © 2011-2022 走看看