@Target (TargetType)
Used to indicate that the type can be applied annotation.
If a annotation does not define a target, then the annotation can appear on any element.
The parameter of target is the java.lang.annotation.elementtype.* type:
ANNOTATION_TYPE:annotation
CONSTRUCTOR:构造方法
- Field: Class field, including enum
- local_variable: Local Variables
- Method: Methods
- Package: Packages
- PARAMETER: Parameters
TYPE:类、接口、annotation、enum
Such as:
This metaannotationtype can only appear when defining annotation
@Target (elementtype.annotation_type) public @Interface metaannotationtype { ...}
@Retention (Tetention-policy)
Retention defines annotation failure timing.
The value is the java.lang.annotation.retentionpolicy.* type, the specific value:
- Source: Only takes effect in the source phase, such as @override, @SuppressWarnings
- Class (default): Invalid when class is loaded, but valid when compiled into a binary file
- Runtime: Will not expire. such as: @Deprecated
Importjava.lang.annotation.Retention;ImportJava.lang.annotation.RetentionPolicy;//This type of annotation does not expire@Retention (retentionpolicy.runtime) @Interfacemyannotation {String stringvalue (); intintvalue ();} Public classMainClass {//at run time, you can get the information of Myannotation@MyAnnotation (stringvalue = "Annotation Example", intvalue = 100) Public Static voidMyMethod () {}}
@Documented
The Java element used to indicate the configuration of this annotation is Javadoc documented.
@Documented @inherited // For descenders of the annotation to the @documented feature automatically // must be there public @Interface inwork { ... /** * Annotated class */ = "")publicclass Mainapp { ...
If you use Javadoc to get the doc document, you will see the Mainapp document
@Configuration
Used to indicate that class can be used by the spring IOC container as a bean definition
Java Annotations List