1.在Maven中加入以下以依赖:
<!-- 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 -->在spring-***.xml中加入spring支持,打开aop功能
头文件声明 :
使用:
4:默认值
public @interface UserdefinedAnnotation { String name() default "zhangsan"; }使用:
5:注意
Annotation是不可以继承其他接口的,这一点是需要进行注意,这也是annotation的一个规定吧。
Annotation也是存在包结构的,在使用的时候直接进行导入即可。
Annotation类型的类型只支持原声数据类型,枚举类型和Class类型的一维数组,其他的类型或者用户自定义的类都是不可以作为annotation的类型,我查看过文档并且进行过测试。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。