1.加入JAR包。出了Spring自身的Jar包还要一些依赖的JAR包。不然会报ClassNotFound。

Student.java

package com.lubby.bean;

import org.springframework.stereotype.Component;
@Component("student")
public class Student {
private String id;
private String name; public Student() {
super();
}
public Student(String id, String name) {
super();
this.id = id;
this.name = name;
}
public void readBook() {
System.out.println("I am reading book now.....");
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

Something.java

package com.lubby.bean;

import org.springframework.stereotype.Component;

@Component("something")
public class Something {
public void borrowBook() {
System.out.println("Borrow the book from library......");
}
public void returnBook() {
System.out.println("Return the book to library........");
}
}

test.xml

<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:aop="http://www.springframework.org/schema/aop"
default-lazy-init="true"
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/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
"> <!-- 自己主动检測并注冊为spring中的bean+启用注解 -->
<context:component-scan base-package="com.lubby.bean"></context:component-scan>
<aop:config>
<aop:aspect ref="something">
<aop:pointcut expression="execution(* com.lubby.bean.Student.readBook(..))" --定义切点为readBook方法
id="readBook" />
<aop:before pointcut-ref="readBook" method="borrowBook" />---在运行readBook方法之前运行borrowBook方法
<aop:after-returning pointcut-ref="readBook" ----在运行readBook方法之后运行returnBook
method="returnBook" />
</aop:aspect>
</aop:config>
</beans>

运行结果

Borrow the book from library......
I am reading book now.....
Return the book to library........

最新文章

  1. Linux超快速安装Ruby on Rails
  2. 2016huasacm暑假集训训练三 C - Til the Cows Come Home
  3. FIJ Jobs – 2013/8/12
  4. C#编写 &quot;Hello,Word!&quot; 您的第一个程序。
  5. struts2的json-default和struts-default的区别
  6. 关于Modelsim仿真速度的优化
  7. Android源码中的FLAG为何使用16进制
  8. 禁止鼠标多次点击选中div中的文字
  9. Extjs之combobox联动
  10. sqlite3---终端操作
  11. yoeman构建Asp.net core项目并且实现分层
  12. Nutch 二次开发之parse正文内容
  13. 编译原理Tiny语言的定义
  14. pom 的scope标签分析
  15. JavaScript 事件总结
  16. 基于Vue的小日历(支持按周切换)
  17. Python 正则表达式 (python网络爬虫)
  18. Apache服务器配置与管理
  19. 杂记:Django和static,Nginx配置路径,json_schema
  20. HttpServletResponse设置下载文件

热门文章

  1. webpack 4.0 报错
  2. uwsgi配置cheaper模式进行自动弹性
  3. [NOI1999]生日蛋糕(搜索)
  4. UML快速理解
  5. bzoj2402 陶陶的难题II 分数规划+树剖+线段树维护凸壳+二分
  6. MAN VGEXTEND
  7. Pyhton爬虫实战
  8. vuex的mapState方法来获取vuex的state对象中属性
  9. 对排序(Sort)的研究
  10. springboot2整合logback.xml动态修改日志打印级别