spring aop 之annotation
1.CutPointInterface
public interface CutPointInterface {
void method();
}
2.CutPointClass
@Component
public class CutPointClass implements CutPointInterface { @Override
public void method() {
// TODO Auto-generated method stub
System.out.println("切点类");
} }
3.AspectClass
@Aspect
public class AspectClass { @Pointcut("execution(* com.lzp.annotationAop.CutPointInterface.method(..))")
public void method(){ } @Before("method()")
public void before(){
System.out.println("之前");
}
@After("method()")
public void after(){
System.out.println("之后");
} }
4.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="cutPointClass" class="com.lzp.annotationAop.CutPointClass"></bean>
<bean id="aspectClass" class="com.lzp.annotationAop.AspectClass"></bean>
<aop:aspectj-autoproxy proxy-target-class="true"/> </beans>
5.mainTest
ApplicationContext context = new ClassPathXmlApplicationContext(
"annotationAop.xml");
CutPointInterface cutPoint= (CutPointInterface) context.getBean("cutPointClass");
cutPoint.method();
注意jdk和aspect版本
JDK1.6 —— aspectJ1.6
JDK1.7 —— aspectJ1.7.3+
参考:http://www.cnblogs.com/xing901022/p/4267563.html
spring aop 之annotation的更多相关文章
- Spring AOP + AspectJ annotation example
In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...
- Spring AOP + AspectJ Annotation Example---reference
In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...
- [转]彻底征服 Spring AOP 之 实战篇
Spring AOP 实战 看了上面这么多的理论知识, 不知道大家有没有觉得枯燥哈. 不过不要急, 俗话说理论是实践的基础, 对 Spring AOP 有了基本的理论认识后, 我们来看一下下面几个具体 ...
- 161110、彻底征服 Spring AOP 之 实战篇
Spring AOP 实战 看了上面这么多的理论知识, 不知道大家有没有觉得枯燥哈. 不过不要急, 俗话说理论是实践的基础, 对 Spring AOP 有了基本的理论认识后, 我们来看一下下面几个具体 ...
- 彻底征服 Spring AOP 之 实战篇
Spring AOP 实战 看了上面这么多的理论知识, 不知道大家有没有觉得枯燥哈. 不过不要急, 俗话说理论是实践的基础, 对 Spring AOP 有了基本的理论认识后, 我们来看一下下面几个 ...
- Spring AOP 实战运用
Spring AOP 实战 看了上面这么多的理论知识, 不知道大家有没有觉得枯燥哈. 不过不要急, 俗话说理论是实践的基础, 对 Spring AOP 有了基本的理论认识后, 我们来看一下下面几个具体 ...
- 基于 Annotation 拦截的 Spring AOP 权限验证方法
基于 Annotation 拦截的 Spring AOP 权限验证方法 转自:http://www.ibm.com/developerworks/cn/java/j-lo-springaopfilte ...
- 菜鸟学习Spring——60s使用annotation实现简单AOP
一.概述. AOP大家都知道切面编程,在Spring中annotation可以实现简单的AOP列子.下面还未大家介绍几个概念: Aspect 对横切性关注点的模块化. Advice 对横切性关注点的具 ...
- Spring中通过Annotation来实现AOP
一.Spring配置文件 <!--通过@AspectJ注解的形式来使用Spring AOP,强制使用CGLIB代理--> <aop:aspectj-autoproxy proxy-t ...
随机推荐
- Java设计模式从精通到入门一 责任链模式
一直都想对设计模式有一个深刻的认识,这样对于阅读源码的时候就不会那么吃力了.于是有了想要记录下设计模式的笔记.打算从自己不怎么熟悉的设计模式开始写,里面穿插着一点自己的想法,希望自己写完后,会又一 ...
- 用一颗学美术的心来理解PID调节
用一颗学美术的心来理解PID调节 泡利 3 个月前 相信大家小时候都画过美术作品吧?(什么?你还是宝宝?)没关系,不管你是文科.理科.工科.艺术还是家里蹲的,这篇文章对你来说一定会简单到爆炸的. 这种 ...
- W3School 学习笔记
网站构建初级教程 1.每个网站开发人员都有必要了解以下几方面的知识: 万维网如何工作 HTML 语言 如何使用层叠样式表 (CSS) JavaScript 编程 XML 标准 服务器脚本技术 使用 S ...
- 常用类及 LeetCode 每日一题
1 日期时间类 在 Java 语言中,是通过时间戳来表示时间的.所谓的时间戳,在 Java 中就是指当前时间距离历元(1970-01-01 00:00:00)的时间间隔,单位是毫秒,所以 Java 中 ...
- Android MediaPlayer架构 -- MediaPlayer的创建过程
本文系作者自己学习之所用,文章内容仅出自作者拙劣之思考,问题之处烦请不吝指教. MediaPlayer 能被用来控制音/视频文件或流媒体的回放.Android中以MediaPlayer类作为音视频播放 ...
- ftp命令详解补充
下面我来详细地介绍一个登陆FTP的命令和步骤吧: FTP命令是Internet用户使用最频繁的命令之一,不论是在DOS还是UNIX操作系统下使用FTP,都会遇到大量的FTP内部命令.熟悉并灵活应用F ...
- Revit API创建标注NewTag
start ; ) { eId = item; } ...
- App架构师实践指南二之App开发工具
App架构师实践指南二之App开发工具 1.Android Studio 2.编译调试---条件断点.右键单击断点,在弹出的窗口中输入Condition条件.---日志断点.右键单击断点,在弹 ...
- GitHub for Windows简单使用
1.什么是Github gitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名gitHub. gitHub于2008年4月10日正式上线,除了git代 ...
- Android性能优化-减小图片下载大小
原文链接 https://developer.android.com/topic/performance/network-xfer.html 内容概要 理解图片的格式 PNG JPG WebP 如何选 ...