使用spring如何对cxf框架进行整合

发布时间:2020-11-24 16:22:42 作者:Leah
来源:亿速云 阅读:158

使用spring如何对cxf框架进行整合?很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

1.创建动态web项目

2.导入cxf和spring相关jar包(CXF核心包:cxf-2.4.2.jar)

3.在web.xml中配置CXF框架的核心Servlet

<servlet>
   <servlet-name>cxf</servlet-name>
   <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
   <init-param>
     <param-name>config-location</param-name>
     <param-value>classpath:applicationContext.xml</param-value>
   </init-param>
 </servlet>
 <servlet-mapping>
   <servlet-name>cxf</servlet-name>
   <url-pattern>/webservice/*</url-pattern>
 </servlet-mapping>

4.提供spring框架的配置文件applicationContext.xml

applicationContext.xml的约束:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://cxf.apache.org/bindings/soap 
          http://cxf.apache.org/schemas/configuration/soap.xsd
          http://cxf.apache.org/jaxws 
          http://cxf.apache.org/schemas/jaxws.xsd">

5.开发一个服务类

注:服务类必须加注解  @WebService

6.在spring中配置文件中注册服务

<jaxws:endpoint id="" address="/hello" implementor=""></jaxws:endpoint>
<!-- id为服务的id,任意填写 address 为访问地址 implementor为服务类的全类名-->

启动web工程,浏览器访问

###客户端

(用wsdl2java命令生成本地代码调用)

1,在wsdl2java.bat命令所在的文件夹下打开命令窗口,输入:wsdl2java -d . 路径

(路径为service发布后页面的wsdl的全路径,service访问的路径名加&#63;wsdl),回车后会在当前文件夹下生成文件夹

2.把文件夹复制到项目中

    (用spring文件注册代理对象调用)

1.创建项目,可以不是web项目,导入jar包

2.将生成的接口复制到项目中。

3.创建applicationContext.xml文件中配置代理对象

<jaxws:client id="" address = "" serviceClass =""></jaxws:client>
<!-- id值随意, adress的值为wsdl的路径值,当不在本机是,须要修改ip serviceClass为接口的全路径-->

4.编写实现类(如下为例子)

public static void main(String[] args) {
    //创建工厂对象
    ClassPathXmlApplicationContext cts = new ClassPathXmlApplicationContext("applicationContext.xml");
    Fun1 proxy = (Fun1) cts.getBean("myclient");
    String string = proxy.sayHello("呵呵", 12);
    System.out.println(string);
  }

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

推荐阅读:
  1. 使用spring怎么对mybatis进行整合
  2. 如何在Spring中利用webservice restful对CXF 进行整合

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

cxf spring

上一篇:如何在Java项目中使用OCR tesseract实现一个图文识别功能

下一篇:在android使用PopupWindow时出现返回键消失如何解决

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》