spring AOP 自定义注解
来源:互联网 发布:cygwin与linux区别 编辑:程序博客网 时间:2024/05/17 08:12
配置
applicationConfig.xml
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop" xmlns:task="http://www.springframework.org/schema/task"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.0.xsd"><context:annotation-config /><task:annotation-driven /><context:component-scan base-package="扫描的包名"><context:exclude-filter type="annotation"expression="org.springframework.stereotype.Controller" /></context:component-scan><aop:aspectj-autoproxy/></bean></beans>spring-mvc.xml
<context:component-scan base-package="<span style="font-family: Arial, Helvetica, sans-serif;">扫描的包名</span><span style="font-family: Arial, Helvetica, sans-serif;">" use-default-filters="false"></span> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan><aop:aspectj-autoproxy proxy-target-class="true" />
自定义的注解
/** * Created by zhonghao.wang on 2016/7/21. */import java.lang.annotation.Documented;import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;//自定义注解相关设置@Target({ElementType.METHOD})@Retention(RetentionPolicy.RUNTIME)@Documentedpublic @interface JspRequest { //自定义注解的属性,default是设置默认值 String desc() default "处理Jsp请求,捕捉异常、打印日志、监控";}
切面
import org.aspectj.lang.ProceedingJoinPoint;import org.aspectj.lang.Signature;import org.aspectj.lang.annotation.Around;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Pointcut;import org.aspectj.lang.reflect.MethodSignature;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.core.annotation.Order;import org.springframework.stereotype.Component;/** * Created by zhonghao.wang on 2016/7/21. */@Component@Order(1)@Aspectpublic class ControllerAspect { public static final String jspRequest = "jspRequest"; @Pointcut("@annotation(com.ucar.ac.common.annotation.JspRequest)") public void pointcut() { } @Around("pointcut()") public String catchException(ProceedingJoinPoint pjp) throws Throwable { Logger logger = getLogger(pjp, jspRequest); try {// Model model = (Model) pjp.getArgs()[1];// Object form = pjp.getArgs()[2]; return (String) pjp.proceed(pjp.getArgs()); } catch (Exception e) { logger.error(e.getMessage(), e); return "/500.jsp"; } } public static Logger getLogger(ProceedingJoinPoint pjp, String tag) { Signature signature = pjp.getSignature(); String monitorKey = "NONE_Interface_MonitorKey"; if (signature instanceof MethodSignature) { MethodSignature methodSignature = (MethodSignature) signature; // 此处需要考虑一下性能问题 // mapping 方法对应的 类全名 + 方法名 monitorKey = tag + "#" + methodSignature.getDeclaringTypeName() + "#" + methodSignature.getName(); } return LoggerFactory.getLogger(monitorKey); }}
0 0
- spring AOP 自定义注解
- Spring AOP自定义注解
- Spring AOP自定义注解 身份验证
- Spring Aop解析自定义注解
- Spring AOP自定义注解 身份验证
- spring自定义注解AOP实现
- java 自定义注解 spring aop 实现注解
- 利用Spring AOP处理自定义注解
- Spring AOP+自定义注解实现缓存
- Spring AOP 自定义注解的实现
- Spring AOP与IOC以及自定义注解
- Spring AOP 自定义注解记录操作日志
- Spring AOP 自定义注解的实现
- spring aop自定义注解实现日志记录
- 利用Spring AOP处理自定义注解
- spring自定义注解实现AOP日志管理
- Spring AOP自定义注解实现权限控制
- Spring Aop +自定义注解实现用户权限控制
- 利用gdb远程调试驱动模块
- Hadoop 入门 云计算概念
- hdu 5774 Bubble Sort(树状数组)
- IDEA 基于Spring + Spring MVC + Mybatis 高性能web构建
- JVM实用参数(八)GC日志
- spring AOP 自定义注解
- js 三种弹窗
- 近期虚拟机相关问题总结
- FFMpeg编译报错
- ubuntu 的 python从2.* 升级到3.*
- Android 多线程 线程池原理 封装线程池
- 【android学习】一个APK的Activity启动另一个APK的Activity
- SessionID
- HTML篇之CSS样式——CSS水平垂直居中对齐(多种方式)