Jenkins部署dubbo:Failed to read schema document 'http://code.alibabatech.com/schema/dubbo/dubbo.xsd'

参考文章:http://blog.csdn.net/snack8310/article/details/52275960 (方便使用,贴出文章片段,如有侵权,请联系删除!)

dubbo项目启动时报错,已经配置eclipse,本地成功,但是Jenkins+maven+github时仍然出错。采用第二种方法。

解决该问题主要有两种办法。 
1. eclipse中修改xml参照路径,索引到本地dubbo.xsd文件(有一定限制),网上查找的大部分为该方法。 
注意在工具自动拼出来的路径后面加上 /dubbo.xsd。就是类似 xxx/dubbo/dubbo.xsd 这样的一行。 
2. 将dubbo.xsd文件编译在工程中(通用) 
将dubbo.xsd保存在工程的classpath目录中,并且在dubbo的XMLschema的参照出,修改为参照项目的工程路径下文件,代码如下:

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://code.alibabatech.com/schema/dubbo classpath:/dubbo.xsd">

本项目由于使用jenkins自动编译,无法通过本地eclipse导入的办法,只能采用办法2,这样其他人修改时也不受影响。唯一的问题是编译的内容略微增加,系统代码有一点点侵入。

注意事项

按照办法2修改时,系统会出现 Unable to locate Spring NamespaceHandler for XML schema namespace 的错误,如下

ERROR org.springframework.web.context.ContextLoader - 
                                                 Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:/beans/dubbo-consumer.xml]
Offending resource: class path resource [beans/applicationContext.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://code.alibabatech.com/schema/dubbo]
Offending resource: class path resource [beans/dubbo-consumer.xml]

就是提示无法指向XMLschema namespace,出现该问题说明刚才的修改已经成功,但是本项目中参照dubbo服务失败,需要在pom文件中显示指定dubbo相关的参照。Provider提供的API中指定的dubbo服务无法使用在本项目中。

 <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.5.3</version>
            <exclusions>
                <exclusion>
                    <artifactId>spring</artifactId>
                    <groupId>org.springframework</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>
如果有打包入口类报错:
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://code.alibabatech.com/schema/dubbo] 
按如下处理:
<build>
		<plugins>
			<!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> 
				<configuration> <source>1.7</source> <target>1.7</target> </configuration> 
				</plugin> -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				<version>3.1.0</version>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<transformers>
								<transformer
									implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
									<resource>META-INF/spring.handlers</resource>
								</transformer>
								<transformer
									implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
								</transformer>
								<transformer
									implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
									<mainClass>org.global.fairy.service.impl.Assembly</mainClass>
								</transformer>
							</transformers>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
增加 
<transformer
									implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
									<resource>META-INF/spring.handlers</resource>
								</transformer>
								<transformer
									implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
								</transformer>
打包入口类的时候,覆盖旧有的spring.schema


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

水上冰石

希望能帮助到你

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值