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 ...
随机推荐
- Manjaro 初始配置----anaconda-pycharm-opencv-tensorflow
1.安装蟒蛇 1)安装 yaourt anaconda source /opt/anaconda/bin/active root 2)添加环境变量 在〜/ .bashrc中添加 export PATH ...
- IPv6升级改造包括什么?
关于IPv6技术升级具体做了什么,在我脑海里只是更换了域名解析的IP而已,所以找了这篇文章,帮助初步解惑. 原文地址:https://www.maczd.com/post/web-ipv6-upgra ...
- vuex数据持久化存储
想想好还是说下vuex数据的持久化存储吧.依稀还记得在做第一个vue项目时,由于刚刚使用vue,对vue的一些基本概念只是有一个简单的了解.当涉及到非父子组件之间通信时,选择了vuex.只是后来竟然发 ...
- Linux开源监控平台 -- Zabbix 小白安装以及使用
安装准备: 1.安装前需要先关闭selinux和firewall. 关闭Linux: [root@zabbix ~]# vi /etc/selinux/config 将SELINUX=enforcin ...
- [ 原创 ] Centos7.6安装Mysql5.7
https://blog.csdn.net/shj_php/article/details/86712408 CentOS7下安装MySQL5.7安装与配置(YUM) http://blog.csdn ...
- TCO 2015 1A Hard.Revmatching(Hall定理)
\(Description\) 给定一个\(n\)个点的二分图,每条边有边权.求一个边权最小的边集,使得删除该边集后不存在完备匹配. \(n\leq20\). \(Solution\) 设点集为\(S ...
- luoguP4709 信息传递 置换 + 多项式exp
感觉我的做法并不是最优做法... 考虑一个置换\(g\)中的一个置换环\(S\) 在\(g^n\)的形态中,它变为了\(gcd(n, |S|)\)个长度相同的置换环 那么,我们考虑对\(f\)的所有置 ...
- 潭州课堂25班:Ph201805201 并发(非阻塞,epoll) 第十课 (课堂笔记)
# -*- coding: utf-8 -*- # 斌彬电脑 # @Time : 2018/7/12 0012 20:29 import socket server = socket.socket() ...
- bzoj 4128 矩阵求逆
/************************************************************** Problem: 4128 User: idy002 Language: ...
- saltstack 命令2
在Salt主机上,可以快速查看所有Salt minion连接,并查看连接是否被接受,拒绝或挂起 [root@node1 ~]# salt-key -L 接受所有的key [root@node1 ~]# ...