cxf在web中与spring集成

cxf version:2.7

jre:1.7

 

建立web工程cxfweb,将cxf的lib目录下面的所有jar包进入到web工程

 

web.xml:

 

  contextConfigLocation

       

  classpath:cxf-servlet.xml

 

  

 

  org.springframework.web.context.ContextLoaderListener

 

  

 

cxf

org.apache.cxf.transport.servlet.CXFServlet

 

cxf

/cxf/*

 

cxf-servlet.xml:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"

xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"

xsi:schemaLocation="http://www.springframework.org/schema/beans 

          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

            http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd

            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd

            http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">

 

 

 

java 代码:

package com.wdh.ws.cxf;

 

import javax.jws.WebService;

import javax.xml.ws.BindingType;

import javax.xml.ws.soap.SOAPBinding;

 

@WebService

@BindingType(SOAPBinding.SOAP12HTTP_BINDING)//sopa 1.2

public interface IHelloService {

 

String sayHello(String name);

}

 

package com.wdh.ws.cxf;

 

public class HelloServiceImpl implements IHelloService {

 

@Override

public String sayHello(String name) {

return "hello " + name;

}

 

}

 

如果我的wen工程路径为:

    http://192.168.1.116:9999/cxfweb

那么该webservice的地址为:

  http://192.168.1.116:9999/cxfweb/cxf/hello?wsdl

 

客户端生成代理对象:

   启动命令行,切换到cxf的bin目录,运行

   D:\apache-cxf-2.7.11\bin>wsdl2java -d e: http://192.168.1.116:9999/cxfweb/cxf/hello?wsdl

 

客户端测试代码:

package com.wdh.ws.cxf;

 

public class CxfTest {

 

public static void main(String[] args) {

IHelloServiceService helloServiceService = new IHelloServiceService();

IHelloService helloService = helloServiceService.getIHelloServicePort();

String str = helloService.sayHello("jack");

System.out.println(str);

}

}

你可能感兴趣的:(webservice)