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 ...
随机推荐
- Avahi DOS攻击broadcast-avahi-dos
Avahi DOS攻击broadcast-avahi-dos Avahi是Linux下常用的类DNS服务.它可以帮助主机在没有DNS服务的局域网中,发现基于Zeroconf协议的设备和服务.该工具 ...
- 安装android studio&flutter
参考:https://flutterchina.club/setup-windows/ 1.安装jdk 2.android studio下载地址 https://developer.android. ...
- 一款易搭建,运行快的Git服务器:Gitea安装教程
说明:Gitea是从Gogs发展而来,同样的拥有极易安装,运行快速的特点,而且更新比Gogs频繁很多,维护的人也多,个人认为Gitea还是更好一些的,这里就说下安装方法. 截图 简介 Gitea是一个 ...
- BZOJ.2069.[POI2004]ZAW(最短路Dijkstra 按位划分)
题目链接 \(Description\) 给定一张带权图(边是双向的,但不同方向长度不同).求从1出发,至少经过除1外的一个点,再回到1的最短路.点和边不能重复经过. \(n\leq5000,m\le ...
- BZOJ2509 : 送分题
求出每个点向上下左右能延伸的最大长度$left$.$right$.$up$.$down$. 枚举每一条对角线,如果$j$可以作为左上角,$i$可以作为右下角,那么有: $j+\min(down[j], ...
- 大数据实践:ODI 和 Twitter (二)
大数据实践:ODI和Twitter(二) 在前面的文章中,我们已经使用flume将数据从twitter抓取到Hive中,现在我们来看看ODI(Oracle Data Integrator)如何在HIV ...
- nginx 负载均衡集群解决方案 healthcheck_nginx_upstreams模块测试 (二)
在这里详细讲解healthcheck_nginx_upstreams模块中存在的bug,对于healthcheck_nginx_upstreams模块的安装和使用请阅读上一篇blog进行学习. 测试环 ...
- PLSQL连接Oracle 数据库配置详解
1. 下载instantclient-basic-win32-11.2.0.1.0 (oracle官网下载地址:http://www.oracle.com/technetwork/topics/win ...
- linux查看及修改文件权限以及相关
linux查看及修改文件权限以及相关 查看文件权限的语句: 在终端输入: ls -l xxx.xxx (xxx.xxx是文件名)那么就会出现相类似的信息,主要都是这些: -rw-rw-r-- 一共有1 ...
- js获取浏览器版本信息整理
一.Navigator 对象 JavaScript Navigator 对象包含了有关访问者浏览器的所有信息.接下来我们学习 Navigator 对象的两个属性. appName 保存浏览器类型 ap ...