日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

WebService--CXF与Spring的整合(jaxws:endpoint形式配置)以及客户端调用(spring配置文件形式,不需要生成客户端代码)

發布時間:2023/12/18 javascript 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WebService--CXF与Spring的整合(jaxws:endpoint形式配置)以及客户端调用(spring配置文件形式,不需要生成客户端代码) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

作者:@展云
本文為作者原創,轉載請注明出處:https://www.cnblogs.com/zhanxiaoyun/p/7942902.html


目錄

一、CXF與Spring整合(jaxws:endpoint形式配置)
1.新建一個maven項目
2.web.xml文件中配置CXFServlet以及Spring容器,配置Spring的配置文件,配置webservice的配置文件
二、客戶端調用(spring配置文件形式,不需要生成客戶端代碼)
1.spring配置文件信息
2.寫對應接口信息
3.加載Spring的配置文件進行測試
4.需要的jar包

一、CXF與Spring整合(jaxws:endpoint形式配置)

工具要點:idea、maven

1.新建一個maven項目

?pom.xml

2.web.xml文件中配置CXFServlet以及Spring容器,配置Spring的配置文件,配置webservice的配置文件

web.xml:

?web.xml

applicationContext.xml:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsd"><!-- 使用annotation 自動注冊bean,并檢查@Required,@Autowired的屬性已被注入 --><context:component-scan base-package="com.wp.learn.webservice"></context:component-scan><!-- 導入其他配置文件 --><import resource="applicationContext-ws.xml" /></beans>

applicationContext-ws.xml:

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"><import resource="classpath:META-INF/cxf/cxf.xml" /><import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /><import resource="classpath:META-INF/cxf/cxf-servlet.xml" /><jaxws:endpoint id="helloWebservice" implementor="#helloServiceImpl"address="/hello" /> </beans>

接口HelloService:

Impl類HelloServiceImpl:

情況一、如果Impl類的注解是@Webservice,implementor需要寫完全路徑

情況二、Impl類注解是@Service,implementor只需“#”號加bean的id名

二、客戶端調用(spring配置文件形式,不需要生成客戶端代碼)

  Webservice的客戶端調用,可以用ajax前端調用,java中可以通過生產客戶端代碼調用,也可以通過Spring配置文件、寫對應接口信息調用。本例介紹配置文件,寫接口信息進行webservice調用。

1.spring配置文件信息

<jaxws:client id="helloService" serviceClass="com.wp.learn.webservice.cxf.service.IHelloService"address="http://localhost:8080/ws/HelloService"> </jaxws:client>

2.寫對應接口信息

?需要注意兩點:

  • 1、targetNamespace的值必須和webservice服務項目中定義的一致,具體信息可以在WSDL文件中查看
  • 2、接口名稱可以自己隨便起,但是方法名稱、參數格式必須保持一致,否則無法找到服務的實現方法。

//注意,該出的targetNamespace的值必須和webService服務項目中定義的必須一致,否則調用不成功 @WebService(targetNamespace = "http://impl.service.cxf.webservice.learn.wp.com/", name = "IHelloService") public interface IHelloService {//接口名稱可以不一樣,方法名稱、參數格式必須保持一致,否則無法找到服務的實現的方法public String sayHi(String name); }

3.加載Spring的配置文件進行測試

public class Test {public static void main(String[] args) {ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-ws.xml");IHelloService helloService = (IHelloService) context.getBean("helloService");String result = helloService.sayHi("帥哥");System.out.print(result);} }

4.需要的jar包

?pom.xml

?源碼地址:https://gitee.com/wangpinggs/learn/tree/master/webserviceDemo

總結

以上是生活随笔為你收集整理的WebService--CXF与Spring的整合(jaxws:endpoint形式配置)以及客户端调用(spring配置文件形式,不需要生成客户端代码)的全部內容,希望文章能夠幫你解決所遇到的問題。

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