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.