使用低版本Dubbo时,因为要与4.x与5.x版本的Spring集成,所以,我们需要做如下修改。
首先需要排除掉dubbo自带的2.5的Spring,所以我使用下面这个配置,前面都是正常的引用Spring 4.x或Spring 5.x。
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>dubbo</artifactId>
<version>2.5.3</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<artifactId>netty</artifactId>
<groupId>org.jboss.netty</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>com.github.sgroschupf</groupId>
<artifactId>zkclient</artifactId>
<version>0.1</version>
</dependency>
二、打包成本地APP
需要使用Shade这个插件来打包,POM配置如下,其中最关键是那两个transformer,保证将spring.handlers和spring.schemas文件能合并起来,否则执行时会报找不到dubbo:application错误,或者说无法处理dubbo:application错,都是因为在缺省的打包模式下,META-INF目录下同名文件是只取第一个,而不会多个合并起来,导致找不到dubbo.xsd以及对应的handler类:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>cn.chinaunicom.woplus.analysis.MongoStatisticServer.App</Main-Class>
<X-Compile-Source-JDK>1.7</X-Compile-Source-JDK>
<X-Compile-Target-JDK>1.7</X-Compile-Target-JDK>
</manifestEntries>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>