Spring中自定义注解与AOP中获取注解
来源:互联网 发布:明天教室 知乎 编辑:程序博客网 时间:2024/05/21 06:54
原文地址:http://blog.csdn.net/qpfjalzm123/article/details/45061701
一、自定义注解(annotation)
自定义注解的作用:在反射中获取注解,以取得注解修饰的类、方法或属性的相关解释。
package me.lichunlong.spring.annotation;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) @Documented public @interface LogAnnotation { //自定义注解的属性,default是设置默认值 String desc() default "无描述信息"; }
二、自定义注解的使用
package me.lichunlong.spring.service;import me.lichunlong.spring.annotation.LogAnnotation;import me.lichunlong.spring.jdbc.JdbcUtil;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;@Servicepublic class UserService { //与其它注解一样的使用 @LogAnnotation(desc="this is UserService") public void add() { System.out.println("UserService add..."); }}
三、AOP中获取注解
//环绕通知:类似与动态代理的全过程 //携带参数ProceedingJoinPoint,且必须有返回值,即目标方法的返回 @Around(value = "execution(* me.lichunlong.spring.service.*.*(..)) && @annotation(log)") public Object aroundMethod(ProceedingJoinPoint pjd, LogAnnotation log) { Object result = null; System.out.println(log.desc()); try { System.out.println("前置通知"); result = pjd.proceed(); System.out.println("后置通知"); } catch (Throwable e) { System.out.println("异常通知"); } System.out.println("返回通知"); return result; }
0 0
- spring中自定义注解(annotation)与AOP中获取注解
- Spring中自定义注解与AOP中获取注解
- spring中自定义注解(annotation)与AOP中获取注解
- spring中自定义注解(annotation)与获取注解
- AOP中获取注解
- spring中 aop注解
- Spring中AOP注解
- Spring中AOP注解实现
- spring中注解实现aop
- spring AOP 自定义注解
- Spring AOP自定义注解
- 在spring的aop中获取自定义注解的参数值,即在切面中获取annotation的参数值
- Spring AOP与IOC以及自定义注解
- Spring中基于配置XML与Annotation注解配置AOP
- AOP中获得自定义注解对象
- java 自定义注解 spring aop 实现注解
- spring中aop的注解配置方式
- Spring的注解Controller中使用AOP
- BypassUAC------BypassUac On Win10 Using Disk Cleanup
- B - FatMouse and Cheese
- 第八周项目3-顺序串算法
- 第八周项目2——建立链串的算法库
- Eclipse完美汉化教程
- Spring中自定义注解与AOP中获取注解
- android通讯录搜索,通过输入框搜索以及侧边litview的滚动搜索,还有单选,全选以及反选的功能
- Linux文件拷贝
- A tool for pushing flv/mp4/ts/rtmp/rtsp/hls source to rtmp/rtspserver.
- 卸载oracle时多次卸载主目录失败
- iOS runtime 关联对象(Associated Object)
- 互联网协议入门(一)
- Spring_任务调度的简单笔记
- 单例类