Examples of Spring combination annotation and meta annotation in JSP, jspspring
Spring combination annotation and Metadata Annotation instances in JSP
Abstract: Annotation is also called metadata. A code-level description. It is at the same level as classes, interfaces, and enumeration. It can be declared before packages, classes, fields, methods, local variables, and method parameters to describe these elements.
1. annotations that can be annotated to other annotations are called meta annotations, and annotations are called combination annotations. Through combination annotations, You can simplify a lot of repetitive annotation operations.
2. Combined annotation of examples
import org.springframework.context.annotation.ComponentScan;import org.springframework.context.annotation.Configuration;import java.lang.annotation.*;@Target(ElementType.TYPE)@Retention(RetentionPolicy.RUNTIME)@Documented@Configuration@ComponentScanpublic @interface GroupAnnotation { String[] value() default {};}
Code explanation: Combine @ Configuration and @ ComponentScan meta annotation, and overwrite the value Parameter
3. Compile common Bean
@ Servicepublic class DemoService {public void sys () {System. out. println ("Comments sample ");}}
4. Configuration classes using composite annotations
@GroupAnnotation("com.xuanwu.annotation")public class DemoConfig {}
5. Run
public class Main { public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DemoConfig.class); DemoService demoService = context.getBean(DemoService.class); demoService.sys(); }}
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!