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项目中即可,如下图所示。

Spring 开发第一步(二)的更多相关文章
- Spring 开发第一步(三)Spring与JDBC
<spring in action 3rd>中的前面4章讲解的是Spring的核心,也就是DI/IOC和AOP .从第5章开始是Spring在企业开发中的各个方面的应用.其实作为笔者从事的 ...
- Spring 开发第一步
经过今天上午的学习发现spring上手开发一个"hello world"真的非常简单. 开发环境搭建: 1.去spring官网下载spring-framework-3.2.11.R ...
- Spring 开发第一步(四)Spring与JDBC事务
Spring使用各种不同的TransactionManager来管理各种不同数据源事务底层(比如jdbc数据源.hibernate数据源.JPA数据源等等).在此基础上使用各种对应的Template来 ...
- 我的自定义框架 || 基于Spring Boot || 第一步
今天在园子里面看到一位大神写的springboot做的框架,感觉挺不错,遂想起来自己还没有一个属于自己的框架,决定先将大神做好的拿过来,然后加入自己觉得需要的模块,不断完善 目前直接复制粘贴过来的,后 ...
- Andriod开发第一步-部署环境(搬运&&总结)
第一步:安装JDK 第二步:配置Windows上JDK的变量环境 第三步:下载安装Eclipse 第四步:下载安装Android SDK 配置了JDK变量环境, ...
- JAVA开发第一步 - JDK安装与配置
JDK的安装与环境变量配置是JAVA开发之路的第一步,很多新人在这一步上就卡了很久,浪费了很多时间,甚至有些人就轻易地“从入门到放弃”了.今天我们就来一步步教你如何打倒这第一只拦路虎. 1.JDK下载 ...
- JDK 安装与环境配置配置——Android开发第一步
什么是JDK? JDK 即 Java Development Kit,Java开发工具包,用来编译 Java 程序.JRE 在接触JDK的过程中,同时了解到 JRE,JRE 即 Java Runtim ...
- ios开发第一步--虚拟机安装MAC OS X
暂时还没买Macbook,先用虚拟机练练手. 先说说准备工作,我是在win8下安装的,这个不是关键的,只要Vmware版本和MAC OS X版本确定就行了,win7下同样可以. 1.虚拟机Vmware ...
- maven版cxf集合spring开发服务端(二)
一.新建一个maven项目 二.pom.xml引入依赖 <dependency> <groupId>org.apache.cxf</groupId> <art ...
随机推荐
- win 下 nginx 的虚拟主机创建
1.在nginx安装目录下的conf下创建vhost目录,用于存放虚拟主机配置文件. 2.在nginx安装目录下的conf/nginx.conf的http{}中加入 include vhost/* ...
- Spring框架整合JUnit单元测试
1. 为了简化了JUnit的测试,使用Spring框架也可以整合测试 2. 具体步骤 * 要求:必须先有JUnit的环境(即已经导入了JUnit4的开发环境)!! * 步骤一:在程序中引入:sprin ...
- 国内maven仓库地址
Maven 中央仓库地址: 1.http://mvnrepository.com/ (推荐) 2.http://mirrors.ibiblio.org/maven2/ 3.http://repo1.m ...
- 调用数据库-corina
pym = mysql(host='#####', port=3306, user='######', password='########', database='algorithm') #查询数据 ...
- 安卓编译 translate error Lint: How to ignore “<key> is not translated in <language>” errors?
Add following at the header of your strings.xml file <resources xmlns:tools="http://schemas. ...
- W-D-S-UART编程
1.协议原理 2.原理框图 3.开发板底板与核心板图 4.开始配置寄存器 a).使相应I/O引脚配置为UART引脚 b).配置数据发送模式 c).设置为中断或查询模式 d).使能串口缓存 e).流量控 ...
- gitlab VS github
gitlab 和 github的比较 GitLab - 基于Git的项目管理软件 GitLab 是一个用于仓库管理系统的开源项目.使用Git作为代码管理工具,并在此基础上搭建起来的web服务.
- Devexpress VCL Build v2013 vol 13.2.4 发布
不说了,自己看吧. What's New in 13.2.4 (VCL Product Line) New Major Features in 13.2 What's New in VCL Pro ...
- 2018.10.14 NOIP训练 圣诞树(简单dp)
传送门 sbDP题. 曾经一直TLE不知道为什么. 这次发现输入有坑233. 代码
- 25. Green Living 绿色生活
25. Green Living 绿色生活 ①We all know that humans are damaging the environment,but what can we do about ...