New Features of JDK 6 9: Common annotations

Source: Internet
Author: User
New Features of JDK 6 9: Common annotations

Common Annotations was originally part of the Java EE 5.0 (JSR 244) specification, and sun now places a part of it in Java SE 6.0. with the addition of the annotation metadata function (JSR 175) to Java SE 5.0, many Java technologies (such as EJB and Web Services) the annotation part is used to replace the XML file to configure running parameters (or support Declarative Programming, such as EJB declarative transactions ), if these technologies define their own annotations for general purposes, it is obviously a bit repetitive. Therefore, it is valuable to define a set of public annotation for other related Java technologies, this avoids repeated construction and ensures consistency between Java SE and Java EE technologies. the following lists the 10 annotations in common annotations 1.0.

Common annotations
Annotation retention Target description
Generated source annotation_type, constructor, field, local_variable, method, package, parameter, type is used to mark the source code generated
Resource runtime type, method, field is used to mark the dependent resources. The Container injects external resource dependencies accordingly. There are two methods: field-based injection and setter-based injection.
Resources runtime type is used to mark multiple external dependencies at the same time. The Container injects all these external dependencies
Postconstruct runtime method indicates the method that runs after the container injects all dependencies for initialization after dependency injection. Only one method can be labeled as postconstruct.
Predestroy runtime method when the object instance is to be deleted from the container, the callback method to be executed must be marked as predestroy
RunAs runtime type is used to mark which security role is used to execute the annotation class method. This security role must be consistent with the security role of the container.
Rolesallowed runtime type, which is used to mark the security role that allows the execution of the labeled class or method. This security role must be consistent with the security role of the container.
Permitall runtime type, method allows all roles to execute labeled classes or methods
Denyall runtime type, method does not allow any role to execute the labeled class or method, indicating that the class or method cannot run in the Java EE container
Declareroles runtime type is used to define security roles that can be verified by applications. isuserinrole is usually used to test security roles.

Note:

1. rolesallowed, permitall, and denyall cannot be applied to a class or method at the same time.

2. The rolesallowed, permitall, and denyall labels on the method will overwrite the rolesallowed, permitall, and denyall labels on the class.

3. RunAs, rolesallowed, permitall, denyall, and declareroles have not been added to Java SE 6.0.

4. the above annotations processing work is done by the Java EE container. Java SE 6.0 only contains the first five annotations definition classes in the table above, and does not contain engines for processing these annotations, this work can be done by the pluggable annotation processing API (JSR 269 ).

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.