Error creating bean with name ‘endpoint‘ defined in class path resource [.../CxfConfig.class]

Spring boot项目整合webservice后,引入阿里云短信包,项目启动报错。


问题描述:

最近一个老项目发送短信的接口需要由网易换成阿里云的,本来其它项目引入都没什么问题,但这个项目之前使用cxf整合过webservice,导入阿里的jar包后,项目启动报错

Error creating bean with name ‘endpoint’ defined in class path resource [ct/edu/lms/web/server/config/CxfConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.xml.ws.Endpoint]: Factory method ‘endpoint’ threw exception; nested exception is javax.xml.ws.WebServiceException:

完整截图:
在这里插入图片描述
引入的包:

		//cxf
 		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web-services</artifactId>
			<version>2.1.4.RELEASE</version>
		</dependency>
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-frontend-jaxws</artifactId>
			<version>3.1.6</version>
		</dependency>
		<dependency>
			<groupId>org.apache.cxf</groupId>
			<artifactId>cxf-rt-transports-http</artifactId>
			<version>3.1.6</version>
		</dependency>

		//阿里云短信
		<dependency>
    		<groupId>com.aliyun</groupId>
    		<artifactId>aliyun-java-sdk-core</artifactId>
    		<version>4.1.0</version>
		</dependency>

原因分析、解决:

报错大概是因为cxf包和阿里云的包中某个xml解析包冲突了,其中有个com.sun.xml.bind是阿里云中的,于是尝试使用exclusions去掉不想要的包,项目启动正常。代码如下:

		<!-- 阿里云短信 -->
		<dependency>
    		<groupId>com.aliyun</groupId>
    		<artifactId>aliyun-java-sdk-core</artifactId>
    		<version>4.1.0</version>
    		<exclusions>
			   <exclusion>
			  	<groupId>com.sun.xml.bind</groupId>
           		<artifactId>jaxb-core</artifactId>
			  </exclusion>
			<exclusion>
			  	<groupId>com.sun.xml.bind</groupId>
           		<artifactId>jaxb-impl</artifactId>
			  </exclusion> 
			</exclusions>
		</dependency>

后续

本以为项目启动不报错就可以了,但短信发送不了!只能继续找原因,到官网查看,发现官网的jar包已经升级到了4.5.3,尝试引入,所有的问题都解决了。

		<!-- 阿里云短信 -->
		<dependency>
    		<groupId>com.aliyun</groupId>
    		<artifactId>aliyun-java-sdk-core</artifactId>
    		<version>4.5.3</version>
		</dependency>

进入包中查看发现新版已经去掉com.sun.xml.bind这两个包了,应该也是修复了相应的bug。


总结

纠结了大半天的问题,升级一下就解决了,还是需要仔细分析问题,从源头找解决办法,特此记录一下。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

qsya

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值