您的位置:首页 > 编程语言 > Java开发

Spring AOP Maven依赖,拦截加注解的方法参数

2014-03-24 12:58 986 查看
<!-- Spring AOP + AspectJ by shipengzhi -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.11</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.1_3</version>
</dependency>
<!-- end -->
@Standardized(type = StandardizedData.CLIPON)public class Main{...}@Before("execution (* org.xx.xx.xx..*.*(@org.xx.xx.xx.xx.xx.Standardized (*),..))")public void standardize(JoinPoint jp) throws Throwable {Object[] args = jp.getArgs();MethodSignature ms = (MethodSignature) jp.getSignature();Method m = ms.getMethod();Annotation[][] parameterAnnotations = m.getParameterAnnotations();for (int i = 0; i < parameterAnnotations.length; i++) {Annotation[] annotations = parameterAnnotations[i];System.out.println("I am checking parameter: " + args[i]);for (Annotation annotation : annotations) {System.out.println(annotation);if (annotation.annotationType() == Standardized.class) {System.out.println("we have a Standardized Parameter with type = "+ ((Standardized) annotation).type());}}}}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: