cxf发布 webservice服务

导包
cxf发布 webservice服务
antlr-2.7.7.jar

aopalliance-1.0.jar

asm-3.3.jar

commons-collections-3.2.1.jar

commons-lang-2.6.jar

commons-logging-1.1.1.jar

cxf-2.4.2.jar

cxf-manifest.jar

cxf-xjc-boolean-2.4.0.jar

cxf-xjc-bug671-2.4.0.jar

cxf-xjc-dv-2.4.0.jar

cxf-xjc-ts-2.4.0.jar

FastInfoset-1.2.9.jar

geronimo-activation_1.1_spec-1.1.jar

geronimo-annotation_1.0_spec-1.1.1.jar

geronimo-javamail_1.4_spec-1.7.1.jar

geronimo-jaxws_2.2_spec-1.0.jar

geronimo-jms_1.1_spec-1.1.1.jar

geronimo-servlet_3.0_spec-1.0.jar

geronimo-stax-api_1.0_spec-1.0.1.jar

geronimo-ws-metadata_2.0_spec-1.1.3.jar

isorelax-20030108.jar

jaxb-api-2.2.1.jar

jaxb-impl-2.2.1.1.jar

jaxb-xjc-2.2.1.1.jar

jettison-1.3.jar

jetty-continuation-7.4.5.v20110725.jar

jetty-http-7.4.5.v20110725.jar

jetty-io-7.4.5.v20110725.jar

jetty-security-7.4.5.v20110725.jar

jetty-server-7.4.5.v20110725.jar

jetty-util-7.4.5.v20110725.jar

joda-time-1.6.2.jar

jra-1.0-alpha-4.jar

js-1.7R2.jar

jsr311-api-1.1.1.jar

msv-core-2010.2.jar

neethi-3.0.1.jar

opensaml-2.4.1.jar

openws-1.4.1.jar

relaxngDatatype-20020414.jar

saaj-api-1.3.jar

saaj-impl-1.3.2.jar

serializer-2.7.1.jar

slf4j-api-1.6.1.jar

slf4j-jdk14-1.6.1.jar

spring-aop-3.0.5.RELEASE.jar

spring-asm-3.0.5.RELEASE.jar

spring-beans-3.0.5.RELEASE.jar

spring-context-3.0.5.RELEASE.jar

spring-core-3.0.5.RELEASE.jar

spring-expression-3.0.5.RELEASE.jar

spring-jms-3.0.5.RELEASE.jar

spring-tx-3.0.5.RELEASE.jar

spring-web-3.0.5.RELEASE.jar

stax2-api-3.1.1.jar

velocity-1.7.jar

woodstox-core-asl-4.1.1.jar

wsdl4j-1.6.2.jar

wss4j-1.6.2.jar

xalan-2.7.1.jar

xml-resolver-1.2.jar

xmlbeans-2.4.0.jar

xmlschema-core-2.0.jar

xmlsec-1.4.5.jar

xmltooling-1.3.1.jar

xsdlib-2010.1.jar
View Code

 

使用父类发布服务
ServerFactoryBean 发布 webservice
 1 package cn.itcast.cxf;

 2 

 3 import org.apache.cxf.frontend.ServerFactoryBean;

 4 

 5 /**

 6  * 使用ServerFactoryBean发布CXF的javase应用

 7  * @author 

 8  *

 9  */

10 public class HelloService {

11     

12     public String sayHello(String name){

13         System.out.println("sayHello called...");

14         return "hello " + name;

15     }

16     

17     public static void main(String[] args) {

18         //获得服务工厂bean

19         ServerFactoryBean bean = new ServerFactoryBean();

20         //绑定服务的发布地址

21         bean.setAddress("http://192.168.151.42:5678/hello");

22         //指定提供服务的类型

23         bean.setServiceClass(HelloService.class);

24         //指定提供服务的实例

25         bean.setServiceBean(new HelloService());

26         //启动服务-----publish

27         bean.create();

28         System.out.println("server ready...");

29     }

30 }

 

 使用子类发布服务

JaxWsServerFactoryBean 类发布 cxf  javase webservice应用
 1 package cn.itcast.cxf;

 2 

 3 import javax.jws.WebService;

 4 import javax.jws.soap.SOAPBinding;

 5 

 6 import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

 7 import org.apache.cxf.wsdl.http.BindingType;

 8 

 9 /**

10  * 使用JaxWsServerFactoryBean发布CXF的javase应用

11  * 必须要在被发布为服务的类上添加@WebService注解,如果不加注解,虽然不

12         出错,但也不会对外暴露任何方法

13  * @author zhaoqx

14  *

15  */

16 @WebService

17 //将服务端改成soap 1.2版本,不加的话发布的是1.1版本的

18 @javax.xml.ws.BindingType(value=javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)

19 public class HiService {

20     public String sayHi(String name){

21         System.out.println("sayHi called...");

22         return "hi " + name;

23     }

24     

25     public static void main(String[] args) {

26         JaxWsServerFactoryBean bean = new JaxWsServerFactoryBean();

27         bean.setAddress("http://192.168.151.42:6789/hi");

28         bean.setServiceClass(HiService.class);

29         bean.setServiceBean(new HiService());

30         bean.create();

31         System.out.println("server ready...");

32     }

33 }

 

你可能感兴趣的:(webservice)