1. 程式人生 > >Spring boot 整合CXF webservice遇到的一些問題及解決,

Spring boot 整合CXF webservice遇到的一些問題及解決,

在spring boot整合CXF開發是遇到的一些問題

    以及整合方式

整合過程

    網上資料引入cxf-spring-boot-starter-jaxws依賴即可

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
    <version>3.1.11</version>
</dependency>

我使用的spring boot 版本為v1.4.1.RELEASE

此時啟動專案會報錯

錯誤資訊:org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'endpoint' defined in class path resource [com/conf/WebServiceConfig.class]: Bean instantiation via factory method failed;

endpoint.publish("/topicServerService")

然後更換了依賴

<dependency>
    <groupId>
org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>3.1.11</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>
3.1.11</version> </dependency>

即可成功釋出服務

 成功整合cxf後,發現只有webservice服務可以正常使用,其他請求url全部無法正常訪問。

然後在cxf 配置檔案中

WebServiceCxfCfg.java

更改此方法名:public ServletRegistrationBean dispatcherServlet()  

@Bean
public ServletRegistrationBean disServlet(){

    return new ServletRegistrationBean(new CXFServlet() , "/services/*");
}

即可成功訪問其他url

評論中說的是public ServletRegistrationBean dispatcherServlet() 把預設對映覆蓋掉了,把這個名字改掉,控制類方法就能訪問了。

更改此方法明後可以正常其他請求url,webservice服務也正常。

查閱網上資料後發現 spring boot 1.4 版本對應cxf-spring-boot-starter-jaxws   3.1.X  版本

                                        spring boot 1.5 版本對應cxf-spring-boot-starter-jaxws   3.2.X  版本

但本人spring boot 1.4引入cxf-spring-boot-starter-jaxws  依賴 3.1.11後,不能正常啟動專案。


在此。我查看了依賴的關係

    發現cxf-spring-boot-starter-jaxws中的cxf相關的包為2.7.4版本。

此時專案啟動報錯,是不能夠釋出服務的。

所以我更換了相關依賴,將其更改cxf的兩個相關依賴。

而在引入cxf3.1.11的相關依賴後,發現專案可以正常啟動。url都可以正常訪問。

所以此問題,可能是cxf-spring-boot-starter-jaxws中cxf的版本過低!不相容的問題。

具體時間關係,不做深究。