Examples of Spring combination annotation and meta annotation in JSP, jspspring

Source: Internet
Author: User

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!

Related Article

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.