Why: An annotation is called a meta-annotation when it is placed on another annotation definition.
2. Which of these annotations is a meta-annotation that you can place on another annotation?
Why:@Documented is used on annotation definitions, so it is a meta-annotation. The other options are made for methods or parameters.
3. Do you need a special declaration to make an annotation a meta-annotation?
Why: No special declaration is needed for an annotation to be a meta-annotation. If an annotation is allowed to be placed on another annotation, it can act as a meta-annotation. By default, an annotation without @Target can be applied to annotation types; however, if @Target is used, ElementType.ANNOTATION_TYPE or ElementType.TYPE must be included.
4. What is the main purpose of using meta-annotations in Spring?
Why: Spring uses meta-annotations to combine multiple annotations into one. This makes configuration shorter and easier for developers.
5. What is a benefit of creating your own annotation from several Spring annotations?
Why: A custom annotation can bundle a group of annotations. You then write one annotation instead of repeating the same group on many methods.
6. Which Spring MVC annotations are good examples of annotations built with meta-annotations?
Why:@GetMapping, @PostMapping and the other request mapping variants are built on top of @RequestMapping using meta-annotations.
7. Do you need to write a custom annotation processor for an annotation that is meta-annotated with Spring annotations?
Why: Spring automatically recognizes meta-annotations that it supports. It passes the work to the processors that already exist for those annotations.
8. A custom annotation is meta-annotated with Spring annotations and is used on a method. How does Spring treat it?
Why: Spring processes the meta-annotations of a custom annotation the same way as if they were written directly on the method.
9. You want a custom annotation to set a fixed HTTP response status on handler methods. Which Spring annotation can you add to it as a meta-annotation?
Why:@ResponseStatus sets the HTTP response status. When it is used as a meta-annotation, the custom annotation brings the same status behavior.
10. What does the following custom annotation do when it is placed on a controller method?
Why: The annotation is meta-annotated with @RequestMapping(method = RequestMethod.GET) and @ResponseBody. Using it gives the method both behaviors.
11. What is the purpose of @AliasFor in a custom annotation that is meta-annotated with another annotation?
Why:@AliasFor connects an attribute of the custom annotation to an attribute of a meta-annotation. A value set on the custom annotation is then passed on to the meta-annotation.