日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

springboot配置cxf

發布時間:2025/7/14 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springboot配置cxf 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.引入兩個需要的jar

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

2.配置webservice類

package com.btw.court.webService;import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService;@WebService public interface PayWebService {@WebMethodString say(@WebParam(name="arg0")String arg0);}

3.配置webservice實現類

package com.btw.court.webService.impl;import com.btw.court.webService.PayWebService;import javax.jws.WebService;@WebService(targetNamespace = "http://say.com")//對應wsdl中的命名空間xmlns:tns public class PayWebServiceImpl implements PayWebService {@Overridepublic String say(String arg0) {return null;}}

4.配置springboot配置類

package com.btw.court.config;import com.btw.court.webService.PayWebService; import com.btw.court.webService.impl.PayWebServiceImpl; import org.apache.cxf.Bus; import org.apache.cxf.bus.spring.SpringBus; import org.apache.cxf.jaxws.EndpointImpl; import org.apache.cxf.transport.servlet.CXFServlet; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;import javax.xml.ws.Endpoint;@Configuration public class WebServiceConfig {@Bean//發布服務名稱,可以訪問該路徑查看擁有的webservicepublic ServletRegistrationBean dispathcherServlet() {return new ServletRegistrationBean(new CXFServlet(), "/service/*");}@Bean(name = Bus.DEFAULT_BUS_ID)public SpringBus springBus() {return new SpringBus();}@Beanpublic PayWebService payWebService() {return new PayWebServiceImpl();}/*** 綁定接口類,描述接口實現方法,以及接口名稱.如果有多個接口需要實現,可以添加多個該方法(設置方法名不同,發布路徑不同即可)* @return*/@Beanpublic Endpoint endpoint() {EndpointImpl endpoint = new EndpointImpl(springBus(), payWebService());endpoint.publish("/ws");return endpoint;} }

此時,我們輸入http://ip:port/service,可以看到如下圖所示內容。左側馬賽克為接口包含的方法,右側為接口的描述,包括發布地址、wsdl和命名空間。

點擊wsdl的路徑,可以看到接口的詳細描述。

?

轉載于:https://www.cnblogs.com/yxth/p/10436377.html

總結

以上是生活随笔為你收集整理的springboot配置cxf的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。