Use Spring to process custom annotations

Source: Internet
Author: User

Use Spring to process custom annotations
Use Spring to process custom annotations. This article only talks about ideas, not code. Two possible methods: spring schema spring aop aspect reference 1

Dubbo service package name: com. alibaba. dubbo. config

Reference 2

Spring mvc package name: org. springframework. web. servlet. config
You can refer to these two implementations and use schema to add custom annotations, process your own annotations, and register the search module.

Add configuration parsing through schema for source code analysis, for example, add a configuration in the spring configuration file. Premise: in dubbo. in xsd, annotation is defined in spring. handlers defines the processing class com. alibaba. dubbo. config. spring. schema. dubboNamespaceHandler and spring. schemas defines the aforementioned file dubbo. in this case, dubbo: annotation in the spring configuration file will be handled by DubboNamespaceHandler, but it only processes some attributes in other cases, while in annotation, just register the AnnotationBean class to the springp container. ParserContext. getRegistry (). registerBeanDefinition (id, beanDefinition); The AnnotationBean class implements the following interfaces: implements DisposableBean, BeanFactoryPostProcessor, BeanPostProcessor, ApplicationContextAware. The BeanFactoryPostProcessor and BeanPostProcessor interfaces can be processed after the class definition is complete. All beans can be processed once. If the annotation Service or Reference is scanned, the processing is ...... Summary

It can be seen that as long as there is a bean implementing the BeanFactoryPostProcessor and BeanPostProcessor interfaces, spring will execute, so the processing of custom annotations can be processed using this method. You do not even need schema. You only need to manually define the bean in the spring configuration file. Of course, it is easier to use schema to process more custom tags. In addition, the schema extension is only used to process more labels and has nothing to do with custom annotations.

Others

There are more custom annotations on the Internet, all of which are based on the AOP method. The @ Aspect method is used to process logs and other things through custom annotations. These methods must be executed before or after the method when the method is called, rather than registering something at the beginning like spring annotations.

 

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.