http://blog.csdn.net/l1028386804/article/details/70040928
Reprint Please specify source: http://blog.csdn.net/l1028386804/article/details/70040928
Dubbo itself is based on the spring environment, but Dubbo Spring was only 2. Version. Now spring has grown to 4.3, and this year (2017) should release Spring 5.
With the hot spring boot, the Java-base configuration spring is becoming more and more popular.
Dubbo + Boot Development mode, is also a more common combination of methods.
However, when using Dubbo in a high-version spring environment with annotation-mode configuration, there are problems with consolidation due to some code version causes.
1. Dubbo Native Annotation Configuration
The Dubbo itself is spring-based and natively provides annotation configurations:
Service Provider configuration:
[HTML] view plain copy <!--Scan Note package path, multiple packets separated by commas, not filled pacakge means to scan all the classes in the current ApplicationContext and <dubbo:anno Tation package= "Com.foo.bar.service"/> Service provider notes:
[Java] view plain copy import Com.alibaba.dubbo.config.annotation.Service; @Service (version= "1.0.0") public class Fooserviceimpl implements Fooservice {//...}
Service Consumer NOTES:
[Java] view plain copy import com.alibaba.dubbo.config.annotation.Reference; Import org.springframework.stereotype.Component; @Component public class Baraction {@Reference (version= "1.0.0") private Fooservice Fooservice; } Service Consumer configuration:
[HTML] view plain copy <!--Scan Note package path, multiple packets separated by commas, not filled pacakge means to scan all the classes in the current ApplicationContext and <dubbo:anno Tation package= "Com.foo.bar.action"/>
With the official example, you can see that Dubbo uses the XML configuration <dubbo:annotation/> To turn on annotation configuration and provides Com.alibaba.dubbo.config.annotation.Service Annotations Perform service registration and provide com.alibaba.dubbo.config.annotation.Reference annotations for service injection.
2. Implementation Mechanism
It can be seen that internal mechanisms are based on <dubbo:annotation/> tags. Through source analysis, Dubbo for Spring XML parsing processing is provided by Com.alibaba.dubbo.config.spring.schema.DubboNamespaceHandler:
Dubbonamespacehandler.java
[Java] view plain copy package Com.alibaba.dubbo.config.spring.schema; Import Org.springframework.beans.factory.xml.NamespaceHandlerSupport; Import com.alibaba.dubbo.common.Version; Import Com.alibaba.dubbo.config.ApplicationConfig; Import Com.alibaba.dubbo.config.ConsumerConfig; Import Com.alibaba.dubbo.config.ModuleConfig;