Spring3基于注释驱动的AOP
2012-11-14 17:19
218 查看
动AOP代理
运行的时候直接运行就ok了.
<!--启动spring的aop自动代理--> <aop:aspectj-autoproxy/>然后再创建一个AOP类
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.pdp.biz.dao.usermanage.UserDAO; /** * ClassName:DemoAop * Reason: TODO ADD REASON * * @author 王涛 * @version * @since Ver 1.1 * @Date 2010-11-24 上午10:25:18 * */ @Aspect @Service public class DemoAop { @Autowired public UserDAO userDao; @After("execution(public * com.pdp.biz.service.usermanage.impl.UserManageServiceImpl.sayhi(..))") public void doAfter(JoinPoint jp) { System.out.println(userDao.findUsersCount(null)); Object[] args = jp.getArgs(); for(Object obj : args){ System.out.println("参数值:"+obj); } System.out.println("后处理切入----------"+jp.getTarget().getClass().getName()+"----"+jp.getSignature().getName()); } }里面的注释分别是@Aspect用于告诉Spring这个是一个需要织入的类,
@After("execution(public * com.pdp.biz.service.usermanage.impl.UserManageServiceImpl.sayhi(..))") public void doAfter(JoinPoint jp) { ... }里面的doAfter方法上面有一行注释,指明这个方法将在UserManageServiceImpl.sayhi(..)方法运行结束之后来执行,参数JoinPoint主要携带了参数值和方法名什么的,到时候自己查查文档就ok了
org.aspectj.langInterface JoinPoint
All Known Subinterfaces: ProceedingJoinPointpublic interface JoinPointProvides reflective access to both the state available at a join point and static information about it. This information is available from the body of advice using the special form
thisJoinPoint. The primary use of this reflective information is for tracing and logging applications.
aspect Logging {before(): within(com.bigboxco..*) && execution(public * *(..)) {System.err.println("entering: " + thisJoinPoint);System.err.println(" w/args: " + thisJoinPoint.getArgs());System.err.println(" at: " + thisJoinPoint.getSourceLocation());}}
Nested Class Summary | |
---|---|
static interface | JoinPoint.EnclosingStaticPart |
static interface | JoinPoint.StaticPartThis helper object contains only the static information about a join point. |
Field Summary | |
---|---|
staticjava.lang.String | ADVICE_EXECUTION |
staticjava.lang.String | CONSTRUCTOR_CALL |
staticjava.lang.String | CONSTRUCTOR_EXECUTION |
staticjava.lang.String | EXCEPTION_HANDLER |
staticjava.lang.String | FIELD_GET |
staticjava.lang.String | FIELD_SET |
staticjava.lang.String | INITIALIZATION |
staticjava.lang.String | METHOD_CALL |
staticjava.lang.String | METHOD_EXECUTIONThe legal return values from getKind() |
staticjava.lang.String | PREINITIALIZATION |
staticjava.lang.String | STATICINITIALIZATION |
staticjava.lang.String | SYNCHRONIZATION_LOCK |
staticjava.lang.String | SYNCHRONIZATION_UNLOCK |
Method Summary | |
---|---|
java.lang.Object[] | getArgs()Returns the arguments at this join point. |
java.lang.String | getKind()Returns a String representing the kind of join point. |
Signature | getSignature()Returns the signature at the join point. |
SourceLocation | getSourceLocation()Returns the source location corresponding to the join point. |
JoinPoint.StaticPart | getStaticPart()Returns an object that encapsulates the static parts of this join point. |
java.lang.Object | getTarget()Returns the target object. |
java.lang.Object | getThis()Returns the currently executing object. |
java.lang.String | toLongString()Returns an extended string representation of the join point. |
java.lang.String | toShortString()Returns an abbreviated string representation of the join point. |
java.lang.String | toString() |
@Testpublic void testgetUsers(){userManageService.sayhi("Hi 大家好~!");}本文出自 “绝缘材料” 博客,请务必保留此出处http://tonyaction.blog.51cto.com/227462/43218
相关文章推荐
- Spring3基于注释驱动的AOP 推荐
- 对驱动中间层基于PassThru中的Protocol.c的注释
- 【第六章】 AOP 之 6.4 基于@AspectJ的AOP ——跟我学spring3
- Spring2.5注释驱动与基于注释的MVC
- Spring2.5注释驱动与基于注释的MVC
- Spring2.5注释驱动与基于注释的MVC
- 基于状态驱动的AOP技术在模块解耦中的应用
- 基于注释的AOP的一个配置文件!
- Spring2.5注释驱动与基于注释的MVC
- Spring2.5注释驱动与基于注释的MVC 推荐
- 详解Linux2.6内核中基于platform机制的驱动模型<强烈推荐,这是一篇学习驱动模型千年一遇的好文章>
- 基于ubuntu-2.6.35内核的SDIO-WiFi驱动移植使其支持WAP
- 基于私有化构造器与析构器的单件模式(singleton) 实现及注释
- Spring AOP使用(基于Annotation)
- spring学习笔记 -- day09 基于注解的Spring中的AOP
- 基于V4L2的视频驱动开发(2)
- Spring Mvc那点事---(29)Spring Mvc基于ProxyFactoryBean的传统AOP使用正则拦截
- 【Spring AOP】基于Schema配置切面
- @Controller(1)基于@注释的控制器配置
- 基于S3C2410的SD卡linux驱动工作原理(一)