`

JDK6的新特性之九:Common Annotations

 
阅读更多

JDK6的新特性之九:CommonAnnotations

Commonannotations原本是JavaEE5.0(JSR244)规范的一部分,现在SUN把它的一部分放到了JavaSE6.0中.随着Annotation元数据功能(JSR175)加入到JavaSE5.0里面,很多Java技术(比如EJB,WebServices)都会用Annotation部分代替XML文件来配置运行参数(或者说是支持声明式编程,如EJB的声明式事务),如果这些技术为通用目的都单独定义了自己的Annotations,显然有点重复建设,所以,为其他相关的Java技术定义一套公共的Annotation是有价值的,可以避免重复建设的同时,也保证JavaSE和JavaEE各种技术的一致性.下面列举出CommonAnnotations1.0里面的10个Annotations

CommonAnnotations
AnnotationRetentionTargetDescription
GeneratedSourceANNOTATION_TYPE,CONSTRUCTOR,FIELD,LOCAL_VARIABLE,METHOD,PACKAGE,PARAMETER,TYPE用于标注生成的源代码
ResourceRuntimeTYPE,METHOD,FIELD用于标注所依赖的资源,容器据此注入外部资源依赖,有基于字段的注入和基于setter方法的注入两种方式
ResourcesRuntimeTYPE同时标注多个外部依赖,容器会把所有这些外部依赖注入
PostConstructRuntimeMETHOD标注当容器注入所有依赖之后运行的方法,用来进行依赖注入后的初始化工作,只有一个方法可以标注为PostConstruct
PreDestroyRuntimeMETHOD当对象实例将要被从容器当中删掉之前,要执行的回调方法要标注为PreDestroy
RunAsRuntimeTYPE用于标注用什么安全角色来执行被标注类的方法,这个安全角色必须和Container的Security角色一致的
RolesAllowedRuntimeTYPE,METHOD用于标注允许执行被标注类或方法的安全角色,这个安全角色必须和Container的Security角色一致的
PermitAllRuntimeTYPE,METHOD允许所有角色执行被标注的类或方法
DenyAllRuntimeTYPE,METHOD不允许任何角色执行被标注的类或方法,表明该类或方法不能在JavaEE容器里面运行
DeclareRolesRuntimeTYPE用来定义可以被应用程序检验的安全角色,通常用isUserInRole来检验安全角色


注意:

1.RolesAllowed,PermitAll,DenyAll不能同时应用到一个类或方法上

2.标注在方法上的RolesAllowed,PermitAll,DenyAll会覆盖标注在类上的RolesAllowed,PermitAll,DenyAll

3.RunAs,RolesAllowed,PermitAll,DenyAll和DeclareRoles还没有加到JavaSE6.0上来

4.处理以上Annotations的工作是由JavaEE容器来做,JavaSE6.0只是包含了上面表格的前五种Annotations的定义类,并没有包含处理这些Annotations的引擎,这个工作可以由PluggableAnnotationProcessingAPI(JSR269)来做
分享到:
评论

相关推荐

    JDK1.6的九大新特性

    JDK1.6的九大新特性 九:Common Annotations 八:对脚本语言的支持 七:用Console开发控制台程序 六:插入式注解处理API(Pluggable Annotation Processing API) 五:轻量级Http Server API 四:使用Compiler API 三...

    JDK 6.2.3文文档.rar

    JDK6新特性目录导航: Desktop类和SystemTray类 JAXB2实现对象与XML之间的映射 StAX Compiler API 轻量级 Http Server API 插入式注解处理API(Pluggable Annotation Processing API) 用Console开发控制台程序 对...

    jdk1.6.0_45

    jdk1.6新特性 1.Desktop类和SystemTray类 2.使用JAXB2来实现对象与XML之间的映射 3.StAX 4.使用Compiler API 5.轻量级Http Server API 6.插入式注解处理API(Pluggable Annotation Processing API) 7.用Console开发...

    JAVA6新特性介绍.zip

    jdk1.6新特性 1.Desktop类和SystemTray类 2.使用JAXB2来实现对象与XML之间的映射 3.StAX 4.使用Compiler API 5.轻量级Http Server API 6.插入式注解处理API(Pluggable Annotation Processing API) 7.用Console开发...

    jdk-9.0.1_doc-all 最新版

    Defines a subset of the Common Annotations API to support programs running on the Java SE Platform. JDK Module Description jdk.accessibility Defines JDK utility classes used by implementors of ...

    Guava 16.0 API (CHM格式)

    Guava 是一个 Google 的基于java1.6的类库集合的扩展项目,包括 collections, caching, primitives support, concurrency libraries, common annotations, string processing, I/O, 等等. 这些高质量的 API 可以使你...

    web项目常用jar包及说明.zip

    3.common-annotations.jar(支持注解的包) 4.aspectjrt.jar(支持AOP的包) 5.aspectjweaver.jar(支持AOP的包) 6.cglib-nodep-2.1_3.jar(支持cglib动态代理的包) 如果用BasicDataSource来配置数据库连接,还要...

    JAX-WS的lib、src和docs

    3.众多元数据(Annotations)会被JAX-WS用来描述Web Services的相关类,包括Common Annotations, Web Services Metadata, JAXB2的元数据和JAX-WS2.0规范自己的元数据. 4.Annotation Processing Tool(APT)是JAX-WS重要的...

    SSH 框架所需JAR包

    3.common-annotations.jar(支持注解的包) 4.aspectjrt.jar(支持AOP的包) 5.aspectjweaver.jar(支持AOP的包) 6.cglib-nodep-2.1_3.jar(支持cglib动态代理的包) 如果用BasicDataSource来配置数据库连接,还要...

    SSH 项目 整合jar包

    3.common-annotations.jar(支持注解的包) 4.aspectjrt.jar(支持AOP的包) 5.aspectjweaver.jar(支持AOP的包) 6.cglib-nodep-2.1_3.jar(支持cglib动态代理的包) 如果用BasicDataSource来配置数据库连接,还要...

    hadoop-3.1.1.3.1.4.0-315.tar.gz

    ambari-2.7.5 编译过程中四个大包下载很慢,所以需要提前下载,包含:hbase-2.0.2.3.1.4.0-315-bin.tar.gz ,hadoop-3.1.1.3.1.4.0-315.tar.gz , grafana-6.4.2.linux-amd64.tar.gz ,phoenix-5.0.0.3.1.4.0-315....

    Windouws 64 位Tomcat7.0.40 + 64位jdk1.7.0u21 绿色版.part1

    Windouws 64 位Tomcat7.0.40 + 64位jdk1.7.0u21 绿色版 part1 纯绿色,官方下载,绝对可用~ 欢迎评论吐槽~ 文件 PATH 列表 │ LICENSE │ NOTICE │ RELEASE-NOTES │ RUNNING.txt │ ├─bin │ bootstrap.jar │...

    springmvc 各种jar包

    8,common-annotations.jar 9,commons-beanutils-1.8.3.jar 10,commons-codec-1.6.jar 11,commons-collections-3.2.1.jar 12,commons-fileupload-1.2.2.jar 13,commons-io-2.2.jar 14,commons-lang-2.6.jar ...

    SSH整合rar包【齐全】

    activation-1.1.1.jar antlr-2.7.7.jar aopalliance-1.0.jar aspectjrt-1.6.12.jar aspectjweaver-1.6.12.jar axiom-api-1.2.12.jar ...lucene-analyzers-common-4.2.0.jar lucene-analyzers-kuromoji-4.2

    jetbrains-jar.zip

    annotations-23.0.0.jar kotlin-maven-plugin-1.3.71.jar kotlin-stdlib-1.3.72.jar kotlin-stdlib-common-1.3.72.jar kotlin-stdlib-jdk7-1.3.72.jar kotlin-stdlib-jdk8-1.3.72.jar

    Hibernate Reference Documentation3.1

    5.5.2. Using JDK 5.0 Annotations 5.6. Generated Properties 5.7. Auxiliary Database Objects 6. Collection Mapping 6.1. Persistent collections 6.2. Collection mappings 6.2.1. Collection foreign keys ...

    前端-后端java的Util类的工具类

    │ │ │ frame-sourcefiles-org.apache.ibatis.logging.jdk14.html │ │ │ frame-sourcefiles-org.apache.ibatis.logging.log4j.html │ │ │ frame-sourcefiles-org.apache.ibatis.logging.log4j2.html │ │ ...

    开发用jar包合集

    pmaven-common-0.8-20100325.jar pmaven-groovy-0.8-20100325.jar reflectasm-1.07-shaded.jar rhino-1.7R3.jar servlet-api-2.5-20081211.jar simple-4.1.21.jar slf4j-api-1.7.7.jar snakeyaml-1.6.jar ...

    dubbo、dubbox编译所需jar包

    maven-plugin-annotations-3.2.jar maven-plugin-api-2.0.9.jar maven-plugin-api-2.0.jar maven-plugin-descriptor-2.0.9.jar maven-plugin-descriptor-2.0.jar maven-plugin-parameter-documenter-2.0.9.jar maven...

    Thinking in Java 4th Edition

    Common pitfalls when using operators ........... 81 Casting operators .................. 81 Truncation and rounding ........... 82 Promotion ................................... 83 Java has no “sizeof...

Global site tag (gtag.js) - Google Analytics