aop注解方式实现日志管理
来源:互联网 发布:淘宝旺旺官网 编辑:程序博客网 时间:2024/05/23 00:39
maven需要的jar:
<dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.7.4</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.7.4</version> </dependency> <dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>2.1_3</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>4.2.5.RELEASE</version> </dependency>
springServlet-mvc.xml:
<!--proxy-target-class="true"强制使用cglib代理 , 如果为false则spring会自动选择 加上proxy-target-class="true"是为了可以拦截controller里面的方法--> <aop:aspectj-autoproxy proxy-target-class="true"/>
自定义注解
import java.lang.annotation.*;@Target({ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface Log { /**模块*/ String module() default ""; /**描述*/ String description() default "";}
切面类
package io.zhijian.log.aop;import io.zhijian.log.annotation.Log;import org.aspectj.lang.ProceedingJoinPoint;import org.aspectj.lang.annotation.Around;import org.aspectj.lang.annotation.Aspect;import java.lang.reflect.Method;/** * 日志切面处理类 */@Aspectpublic class LogAspect { /** * 日志切入点 */ private LogPoint logPoint; /** * 保存系统操作日志 * * @param joinPoint 连接点 * @return 方法执行结果 * @throws Throwable 调用出错 */ @Around(value = "@annotation(io.zhijian.log.annotation.Log)") public Object save(ProceedingJoinPoint joinPoint) throws Throwable { /** * 解析Log注解 */ String methodName = joinPoint.getSignature().getName(); Method method = currentMethod(joinPoint, methodName); Log log = method.getAnnotation(Log.class); /** * 日志入库 */ if (log != null) { logPoint.save(joinPoint, methodName, log.module(), log.description()); } /** * 方法执行 */ return joinPoint.proceed(); } /** * 获取当前执行的方法 * * @param joinPoint 连接点 * @param methodName 方法名称 * @return 方法 */ private Method currentMethod(ProceedingJoinPoint joinPoint, String methodName) { /** * 获取目标类的所有方法,找到当前要执行的方法 */ Method[] methods = joinPoint.getTarget().getClass().getMethods(); Method resultMethod = null; for (Method method : methods) { if (method.getName().equals(methodName)) { resultMethod = method; break; } } return resultMethod; } public LogPoint getLogPoint() { return logPoint; } public void setLogPoint(LogPoint logPoint) { this.logPoint = logPoint; }}
controller应用日志
@RequestMapping("/xx.do") @Log(module="模块:",description="描述")//注意:这个不加的话,这个方法的日志记录不会被插入 public ModelAndView skipPage(HttpServletRequest request,HttpServletResponse response) throws IOException{ }
可参考:http://www.cnblogs.com/jianjianyang/p/4910851.html
http://blog.csdn.net/pangliang_csdn/article/details/68946506
阅读全文
0 0
- aop注解方式实现全局日志管理
- aop注解方式实现日志管理
- Spring AOP 自定义注解方式实现实现日志管理
- spring AOP自定义注解方式实现日志管理
- SpringMVC自定义注解的方式AOP实现 日志管理
- spring AOP自定义注解方式实现日志管理
- spring AOP自定义注解方式实现日志管理 详解
- spring AOP自定义注解方式实现日志管理
- spring AOP自定义注解方式实现日志管理
- 利用spring AOP注解实现日志管理
- spring自定义注解实现AOP日志管理
- 注解方式实现aop权限管理
- aop:aspectj-autoproxy, SpringAOP拦截Controller,Service实现日志管理(自定义注解的方式)
- Spring MVC AOP通过注解方式拦截Controller等实现日志管理
- Spring MVC AOP通过注解方式拦截Controller等实现日志管理
- Spring AOP拦截Service实现日志管理(自定义注解的方式)
- Spring MVC AOP通过自定义注解方式拦截Controller等实现日志管理
- Spring Aop自定义注解拦截Controller实现日志管理
- Intellij IDEA for mac 破解
- Kaldi语音识别工具包简介及安装说明
- 高通平台使用64位win7系统无法安装驱动的解决方法
- IBM Rational AppScan使用详细说明
- tween和frame 动画
- aop注解方式实现日志管理
- DUBBO 详细介绍
- Realm for Android 使用入门
- 四个数字:1、2、3、4,能组成多少个互不
- jvm内存溢出实例一
- Dmitry
- 《Java核心技术(卷一)》读书笔记——第六章:内部类
- 《neural network and deep learning》题解——ch03 其他技术(momentun,tanh)
- __str__