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 ...
随机推荐
- Chameleon
# -*- coding: utf-8 -*- """ Created on Tue Dec 18 09:55:16 2018 @author: Mark,LI &quo ...
- Docker备忘录
centOS安装教程:https://docs.docker-cn.com/engine/installation/linux/docker-ce/centos/ 一.常用命令 docker buil ...
- Android-LruCache与DiskLruCache
Android LruCache与DiskLruCache 学习自 Android开发艺术探索 https://blog.csdn.net/guolin_blog/article/details/28 ...
- RecylerView动画组件RecylerViewAnimators
RecylerView动画组件RecylerViewAnimators RecyclerView是比ListView和GridView更为强大的布局视图,可以用于展现大量的数据.RecylerVi ...
- [NOIP2017]逛公园 最短路+拓扑排序+dp
题目描述 给出一张 $n$ 个点 $m$ 条边的有向图,边权为非负整数.求满足路径长度小于等于 $1$ 到 $n$ 最短路 $+k$ 的 $1$ 到 $n$ 的路径条数模 $p$ ,如果有无数条则输出 ...
- 洛谷.2292.[HNOI2004]L语言(Trie DP)
题目链接 /* 简单的DP,查找是否有字典中的单词时在Trie树上做 要注意在最初Match(0)一遍后,i还是要从0开始匹配,因为如果有长度为1的单词,Match(i+1)不会从1更新 1M=102 ...
- socket 远程命令
# -*- coding: utf-8 -*- # 斌彬电脑 from socket import * import subprocess server = socket(AF_INET, SOCK_ ...
- C++泛型编程(2)--通过排序和查找元素理解迭代器
许多C++开源库(stl,opencv,ros和blas等)都使用了大量的泛型编程的思想,如果不理解这些思想,将很难看懂代码,而<泛型编程与STL>一书对理解泛型编程思想非常的有帮助,这里 ...
- ie6定位absolute bug触发layout解决
IE6中很多Bug都可以通过触发layout得到解决,以上的解决方法无论是设置zoom:1还是设置width和height其实都是为了触发layout.下列的CSS属性或取值会让一个元素获得layou ...
- webbench进行压力测试
参考原文:http://www.vpser.net/opt/webserver-test.html webbench是Linux下的一个网站压力测试工具,最多可以模拟3万个并发连接去测试网站的负载能力 ...