使用spring2.x的aop aspectj的首先需要添加asm-2.2.2.jar、asm-commons-2.2.2.jar和asm-util-2.2.2.jar,还有aspectjrt.jar和aspectjweaver.jar类包的路径之中。如果在tomcat中使用,还需要spring-tomcat-weaver.jar。
之后再配置文件中只要加入以下代码,就可以使用annotations,比较便捷的使用aop了。
<aop:aspectj-autoproxy/>
一个简单的log aop类
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class AOPServiceLogger {
public static final String ServiceEDP = "execution( * org.aaa.bbb.service.implement..*.*(..))";
public static final String DAOEDP = "execution( * org.aaa.bbb.dao.hibernate..*.*(..))";
private SRLogger log = SRLogger.getLogger(AOPServiceLogger.class);
@Around(ServiceEDP)
// spring中Around通知
public Object logAround(ProceedingJoinPoint joinPoint) {
log.info("Enter Service method : " + joinPoint.getSignature().getName() + " in class " +joinPoint.getTarget());
Object[] args = joinPoint.getArgs();
Object obj = null;
try {
obj = joinPoint.proceed(args);
} catch (Throwable e) {
log.error(e);
e.printStackTrace();
}
log.info("Exit Service method : " + joinPoint.getSignature().getName() + " in class " +joinPoint.getTarget());
return obj;
}
@Around(DAOEDP)
// spring中Around通知
public Object logAroundDAO(ProceedingJoinPoint joinPoint) {
log.info("Enter DAO method : " + joinPoint.getSignature().getName() + " in class " +joinPoint.getTarget());
Object[] args = joinPoint.getArgs();
Object obj = null;
try {
obj = joinPoint.proceed(args);
} catch (Throwable e) {
log.error(e);
e.printStackTrace();
}
log.info("Exit DAO method : " + joinPoint.getSignature().getName() + " in class " +joinPoint.getTarget());
return obj;
}
}
分享到:
相关推荐
Spring AOP的AspectJ支持jar包; 包括: com.springsource.net.sf.cglib-2.2.0.jar com.srpingsource.org.aopalliance-1.0.0.jar com.srpingsource.org.aspectj.weaver-1.68.RELEASE.jar
主要介绍了Spring AOP AspectJ使用及配置过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
包含学习Spring AOP以及学习Spring Aspect J需要新增的jar包,需要的朋友可以下载哦!
aspectj的jar spring使用aop需要的jar 使用aop
Spring 使用AspectJ 实现 AOP(基于xml文件、基于注解)
主要对Spring AOP的相关概念和简单的静态代理、动态代理以及常见的几种AOP配置方式做总结学习。主要包括:1. AOP的常见概念 2. 静态代理 3. jdk动态代理 4. Aspectj and Aspectjweaver 5. **aop-config** 6. CGLIB ...
Spring 使用AspectJ 实现 AOP之前置通知小例子,实际跑过,验证可信。
一个基于@AspectJ的spring2.0 AOP应用实例,很小很简单,没有任何额外信息,最适合AOP入门学习。使用log4j打印信息。把项目直接import进myeclipse就可以使用啦......
以公司订单管理的模型为例(大部分步骤和业务了逻辑已经删除,只保存AOP注解这一部分)Spring AOP
Spring spectJ AOP 前置通知 后置通知 返回通知 异常通知 环绕通知
Spring AOP之基于AspectJ注解总结与案例 ,具体效果和过程看博文 http://blog.csdn.net/evankaka/article/details/45394409
@AspectJ配置Spring AOP,文档,Aspect jar包, 可运行的demo,
When to use Spring AOP and AspectJ AOP? Expert author Ramnivas Laddad shows how to combine technologies such as Spring, Hibernate, Swing, and JDBC with AspectJ. The book fully covers the latest ...
下面小编就为大家分享一篇Spring Aop之AspectJ注解配置实现日志管理的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
NULL 博文链接:https://quicker.iteye.com/blog/670885
spring和aspectj的aop实验,详细内容可以移步至博客:https://mp.csdn.net/postedit/97750888
NULL 博文链接:https://rain1109.iteye.com/blog/1838100
spring aop 自定义切面示例 aspectj 需要相应的架包支持
Spring4.3.7的AOP依赖包-AspectJ
Spring是方法级别的AOP框架,而我们主要也是以某个类的某个方法作为切点,用动态代理的理论来说,就是要拦截哪个方法织入对应AOP通知。 代码清单:打印角色接口