提示:先看Spring版的教程,默認有Spring版基礎
<parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.3.RELEASE</version><relativePath/></parent><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><scope>runtime</scope><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope><exclusions><exclusion><groupId>org.junit.vintage</groupId><artifactId>junit-vintage-engine</artifactId></exclusion></exclusions></dependency><!--CXF做 WebService--><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-spring-boot-starter-jaxrs</artifactId><version>3.4.0</version></dependency><dependency><groupId>org.apache.cxf</groupId><artifactId>cxf-spring-boot-starter-jaxws</artifactId><version>3.4.0</version></dependency><!--引入mybatis--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.2</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.38</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.19</version></dependency><!--工具類--><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.11</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.5.1</version></dependency><!--JSON依賴--><dependency><groupId>org.json</groupId><artifactId>json</artifactId><version>20180813</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.73</version></dependency><!--緩存--><dependency><groupId>net.jodah</groupId><artifactId>expiringmap</artifactId><version>0.5.8</version></dependency><!--雜項--><dependency><groupId>commons-logging</groupId><artifactId>commons-logging</artifactId><version>1.2</version></dependency><dependency><groupId>org.apache.httpcomponents</groupId><artifactId>httpclient</artifactId><version>4.5.2</version></dependency><dependency><groupId>io.jsonwebtoken</groupId><artifactId>jjwt</artifactId><version>0.9.0</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
跨平臺數據交互需要使用 WSDL ,例如A平臺使用 .NET開發,B平臺使用 Java開發,雙方需要對接,因此需要使用 WSDL。無論是 SOAP 的還是 Restful 風格,webservice的效率都要比同平臺直接對接效率低
開發文檔中會包含WSDL鏈接,想要看懂wsdl實際上沒有必要,如果有需要可以查看
https://www.cnblogs.com/wangsen/p/5777541.html
java調用webservice接口 三種方法、如果沒有 WSDL地址,可以參考這篇文章:
https://wangmaoxiong.blog.csdn.net/article/details/87370571
//省略項目本身的service實現邏輯,需要調用第三方服務的時候寫下面的代碼String address = "http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl";//文檔里的WSDL地址JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();factoryBean.setAddress(address); // 設置代理地址factoryBean.setServiceClass(IpAddressSearchWebServiceSoap.class); // 設置接口類型,直白點就是填上反編譯出來的需要調用的接口IpAddressSearchWebServiceSoap userWebService = (IpAddressSearchWebServiceSoap) factoryBean.create();// 創建一個代理接口實現ArrayOfString geoIPContext = userWebService.getGeoIPContext();//獲取接口里你需要使用的方法System.out.println(geoIPContext);
* @Path:作用在方法上,代表當前服務方法的訪問路徑
* @GET/@DELETE/@PUT/@POST: (請求方式->查、刪、更新、插入)
* @PathParam: 作用在參數上,相當于MVC的@PathVariable (書寫路徑參數的別名)
* @Produces: 作用在方法上,控制請求的返回類型
@Configuration
public class CXFConfig {@Autowiredprivate Bus bus;@Autowiredprivate UserWebService userWebService;/*相當于以前的 Web.xml代理 Webservice服務*/@Beanpublic ServletRegistrationBean cxfservlet(){return new ServletRegistrationBean(new CXFServlet(),"/cxf/*");}/*服務注冊*/@Beanpublic Endpoint userEndpoint(){EndpointImpl endpoint = new EndpointImpl(bus,userWebService);endpoint.publish("/wb");return endpoint;}
}
***************************APPLICATION FAILED TO START***************************Description:The Bean Validation API is on the classpath but no implementation could be foundAction:Add an implementation, such as Hibernate Validator, to the classpathProcess finished with exit code 1
原因是SpringBoot版本和 CXF版本不匹配,SpringBoot2.3以上需要使用3.4.0+版本的CXF依賴
***************************
APPLICATION FAILED TO START
***************************Description:Parameter 0 of method errorPageCustomizer in org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration required a bean of type 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath' that could not be found.The following candidates were found but could not be injected:- Bean method 'dispatcherServletRegistration' in 'DispatcherServletAutoConfiguration.DispatcherServletRegistrationConfiguration' not loaded because DispatcherServlet Registration found non dispatcher servlet dispatcherServletAction:Consider revisiting the entries above or defining a bean of type 'org.springframework.boot.autoconfigure.web.servlet.DispatcherServletPath' in your configuration.Process finished with exit code 1
原因是在配置文件中編寫代理 Webservice服務的時候,名稱沖突,改一下圖下方法名即可解決
@Beanpublic ServletRegistrationBean 改成其他方法名(){return new ServletRegistrationBean(new CXFServlet(),"/cxf/*");}
包含Spring版本的Servie + Client,SpringBoot的 Client、直接調用的Service和Client
https://gitee.com/dmbjzorg/Webservice.git
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态