spring 注解实现 无接口 aop
2013-12-26 16:43
417 查看
首先 在application.xml 配置
下面是切面处理的类 需要的jar(aspectjrt-1.7.0.jar,aspectjweaver-1.7.3.jar,aopalliance-1.0.jar还有就是spring的aop了)
<context:annotation-config /><!-- 开启注释配置 --> <aop:aspectj-autoproxy /><!-- 开启切面自动代理 -->
并且需要 aop的命名空间 xmlns:aop="http://www.springframework.org/schema/aop"
下面是切面处理的类 需要的jar(aspectjrt-1.7.0.jar,aspectjweaver-1.7.3.jar,aopalliance-1.0.jar还有就是spring的aop了)
package com.epdc.common.proxy; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.springframework.stereotype.Component; /** * * 通过aop拦截后执行具体操作 */ @Aspect @Component public class LogIntercept { @Pointcut("execution(public * com.epdc.service.ProxyService.proxyService(String,int))") //被拦截的方法 public void proxyService(){ } @Before("proxyService()") public void before() { this.printLog("@Before 方法执行前"); } @Around("proxyService()") public void around(ProceedingJoinPoint pjp) throws Throwable{ this.printLog("@Around 方法执行前"); Object[] objects = pjp.getArgs(); for (int i = 0; i < objects.length; i++) { System.out.println("方法参数"+objects[i]); } Object o = pjp.proceed(); System.out.println("返回的值"+(o==null)); this.printLog("@Around 方法执行后"); } @After("proxyService()") public void after() { this.printLog("@After 方法执行后"); } private void printLog(String str){ System.out.println(str); } }
相关文章推荐
- Spring+SpringMVC+Mybatis 利用AOP自定义注解实现可配置日
- SpringAOP拦截Controller,Service实现日志管理(自定义注解的方式)
- 使用Spring的注解方式实现AOP
- Spring AOP自定义注解实现系统日志记录管理
- 基于注解实现Spring AOP 二-----踩过的坑
- Spring Aop之AspectJ注解配置实现日志管理
- Spring 注解方式实现AOP
- Spring 通过AOP 来实现前置,环绕,异常通知,注解
- 注解方式实现spring-aop
- Spring学习--用 ASpectJ 注解实现 AOP
- spring源码剖析(五)利用AOP实现自定义Spring注解
- Spring 代理对象,cglib,jdk的问题思考,AOP 配置注解拦截 的一些问题.为什么不要注解在接口,以及抽象方法.
- 类继承/接口实现时Spring AOP切入点注意事项
- SpringAOP拦截Controller,Service实现日志管理(自定义注解的方式)
- ITCAST视频-Spring学习笔记(使用Spring的注解方式实现AOP的细节)
- 使用Spring的注解方式实现AOP的细节
- 从头认识Spring-3.7 简单的AOP日志实现(注解版)-增加检查订单功能
- Spring Boot使用AOP实现REST接口简易灵活的安全认证
- SpringAOP拦截Controller,Service实现日志管理(自定义注解的方式)
- Tuscany implementation.spring中@Service注解实现多重接口的...