首页 > 代码库 > JAVA 常用注解( JDK, Spring, AspectJ )

JAVA 常用注解( JDK, Spring, AspectJ )

JDK自带注解

  @Override

  表示当前方法覆盖了父类的方法

  @Deprecation

  表示方法已经过时,方法上有横线,使用时会有警告

  @SuppviseWarnings

  表示关闭一些警告信息(通知java编译器忽略特定的编译警告)

Spring注解

  @Autowired

  spring 自动装配

  @Qualifier(“JavaBea”)

  配合 @Autowired 实现自动装配

  @Resource(name="JavaBean")

  spring 自动装配, 不写参数直接装配同类型的类

  @PostConstruct

  类初始化的方法

  @PreDestroy

  类销毁的方法

  @Component

  表名类为 JavaBean

  @Scope(“prototype” )

  指定Bean的作用范围, prototype为每次都重新实例化

  @Repository

  与 @Component 作用相同, 常用于数据持久层

  @Service

  与 @Component 作用相同, 常用于业务逻辑层

  @Controller

  与 @Component 作用相同, 常用于控制表现层

AspectJ注解

  @AspectJ

  声明切面类, 配合 @Component 使用

  @Before

  前置通知 ( pointcut=”” )  ->  ( 切点表达式 )  

  @AfterReturning

  返回通知 ( pointcut=””, returning=”” ) -> ( 切点表达式, 返回值变量 )

  @AfterThrowing

  异常通知 ( pointcut=””, throwing=”” ) -> ( 切点表达式, 异常变量 )

  @After

  后置通知 ( pointcut=”” ) -> ( 切点表达式 )

  切点表达式

  execution ( 作用域 返回值类型 全类名.方法名() )

  @Around

  环绕通知 ( 切点表达式 )

  @AspectJ

  引入声明在切面中使用

  @Poincut

  重用切点表达式 ( 切点表达式 ), 使用时, 通知的 pointcut=”方法名”

  @Order

  切面类的优先级 ( 数字 ), 数字越小, 优先级越高

 

JAVA 常用注解( JDK, Spring, AspectJ )