Dubbo:关于与高版本的Spring集成的事情

使用Dubbo时,因为要与4.x版本的Spring,所以,我们需要做如下修改。
一,与4.x版本的Spring共存
首先需要排除掉dubbo自带的2.5的Spring,所以我使用下面这个配置,前面都是正常的引用Spring 4.1.6.RELEASE。

<dependency>
            <groupId>com.alibabagroupId>
            <artifactId>dubboartifactId>
            <version>2.5.3version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframeworkgroupId>
                    <artifactId>springartifactId>
                exclusion>
                <exclusion>
                    <artifactId>nettyartifactId>
                    <groupId>org.jboss.nettygroupId>
                exclusion>
            exclusions>
        dependency>
        <dependency>
            <groupId>org.apache.zookeepergroupId>
            <artifactId>zookeeperartifactId>
            <version>3.4.6version>
        dependency>
        <dependency>
            <groupId>com.github.sgroschupfgroupId>
            <artifactId>zkclientartifactId>
            <version>0.1version>
        dependency>

二,打包成本地APP
需要使用Shade这个插件来打包,POM配置如下,其中最关键是那两个transformer,保证将spring.handlers和spring.schemas文件能合并起来,否则执行时会报找不到dubbo:application错误,或者说无法处理dubbo:application错,都是因为在缺省的打包模式下,META-INF目录下同名文件是只取第一个,而不会多个合并起来,导致找不到dubbo.xsd以及对应的handler类:

<plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-shade-pluginartifactId>
                <version>2.4.2version>
                <configuration>
                    <transformers>
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <manifestEntries>
                                <Main-Class>cn.chinaunicom.woplus.analysis.MongoStatisticServer.AppMain-Class>
                                <X-Compile-Source-JDK>1.7X-Compile-Source-JDK>
                                <X-Compile-Target-JDK>1.7X-Compile-Target-JDK>
                            manifestEntries>
                        transformer>
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                            <resource>META-INF/spring.schemasresource>
                        transformer>
                        <transformer
                            implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                            <resource>META-INF/spring.handlersresource>
                        transformer>
                    transformers>
                configuration>
                <executions>
                    <execution>
                        <phase>packagephase>
                        <goals>
                            <goal>shadegoal>
                        goals>
                    execution>
                executions>
            plugin>

你可能感兴趣的:(ALL,IS,JAVA,分布式计算)