• Spring 开发第一步(二)


        今天继续学习《Spring in action 3rd》并运行书中的例子,到了第4章aop,是加入一个作为切面的Audience类,将Performer的perform()方法作为切点来进行切入。

    相关代码:

    <aop:aspect ref="audience">
            <aop:pointcut id="performance" expression="execution(* com.springinaction.springidol.Performer.perform(..))" />
            <aop:before pointcut-ref="performance" method="takeSeats"/>
            <aop:before pointcut-ref="performance" method="turnOffCellphone"/>
            <aop:after-returning pointcut-ref="performance" method="applaud"/>
            <aop:after-throwing pointcut-ref="performance" method="demandRefund"/>
        </aop:aspect>
    package com.springinaction.springidol;
    
    public class Audience {
        public void takeSeats(){
            System.out.println("The audience is taking their seats.");
        }
        public void turnOffCellphone(){
            System.out.println("The audience is turning off their cellphones.");
        }
        public void applaud(){
            System.out.println("CLAP CLAP CLAP CLAP.");
        }
        public void demandRefund(){
            System.out.println("Boo! We want out money back!");
        }
    }

    这样在测试的时候报以下2个错误:

    java.lang.NoClassDefFoundError:org/aopalliance/aop/Advice
    java.lang.NoClassDefFoundError: org/aspectj/weaver/BCException

    我们需要在之前导入的spring-framework-3.2.11.RELEASE-dist.zip基础上,再导入com.springsource.org.aopalliance-1.0.0.jar、aspectj-1.6.13.jar两个包。它们都可以在各自的官方网站上下载。

    特别的是,直接导入aspectj-1.6.13.jar是不行的,需要将其解压缩,然后将解压出来的aspectjrt.jar、aspectjtools.jar、aspectjweaver.jar、org.aspectj.matcher.jar导入eclipse项目中即可,如下图所示。

  • 相关阅读:
    mysql 版本查看
    js 中文乱码
    浏览器内核
    Squid 代理服务器
    minicygwin
    firefox 插件开发
    ocx c++
    NetBeans
    android 虚拟机
    ExpandableListView
  • 原文地址:https://www.cnblogs.com/lyhero11/p/4055348.html
Copyright © 2020-2023  润新知