cxf發布 webservice服務

來源:互聯網
上載者:User

標籤:style   class   blog   code   java   http   

導包
antlr-2.7.7.jaraopalliance-1.0.jarasm-3.3.jarcommons-collections-3.2.1.jarcommons-lang-2.6.jarcommons-logging-1.1.1.jarcxf-2.4.2.jarcxf-manifest.jarcxf-xjc-boolean-2.4.0.jarcxf-xjc-bug671-2.4.0.jarcxf-xjc-dv-2.4.0.jarcxf-xjc-ts-2.4.0.jarFastInfoset-1.2.9.jargeronimo-activation_1.1_spec-1.1.jargeronimo-annotation_1.0_spec-1.1.1.jargeronimo-javamail_1.4_spec-1.7.1.jargeronimo-jaxws_2.2_spec-1.0.jargeronimo-jms_1.1_spec-1.1.1.jargeronimo-servlet_3.0_spec-1.0.jargeronimo-stax-api_1.0_spec-1.0.1.jargeronimo-ws-metadata_2.0_spec-1.1.3.jarisorelax-20030108.jarjaxb-api-2.2.1.jarjaxb-impl-2.2.1.1.jarjaxb-xjc-2.2.1.1.jarjettison-1.3.jarjetty-continuation-7.4.5.v20110725.jarjetty-http-7.4.5.v20110725.jarjetty-io-7.4.5.v20110725.jarjetty-security-7.4.5.v20110725.jarjetty-server-7.4.5.v20110725.jarjetty-util-7.4.5.v20110725.jarjoda-time-1.6.2.jarjra-1.0-alpha-4.jarjs-1.7R2.jarjsr311-api-1.1.1.jarmsv-core-2010.2.jarneethi-3.0.1.jaropensaml-2.4.1.jaropenws-1.4.1.jarrelaxngDatatype-20020414.jarsaaj-api-1.3.jarsaaj-impl-1.3.2.jarserializer-2.7.1.jarslf4j-api-1.6.1.jarslf4j-jdk14-1.6.1.jarspring-aop-3.0.5.RELEASE.jarspring-asm-3.0.5.RELEASE.jarspring-beans-3.0.5.RELEASE.jarspring-context-3.0.5.RELEASE.jarspring-core-3.0.5.RELEASE.jarspring-expression-3.0.5.RELEASE.jarspring-jms-3.0.5.RELEASE.jarspring-tx-3.0.5.RELEASE.jarspring-web-3.0.5.RELEASE.jarstax2-api-3.1.1.jarvelocity-1.7.jarwoodstox-core-asl-4.1.1.jarwsdl4j-1.6.2.jarwss4j-1.6.2.jarxalan-2.7.1.jarxml-resolver-1.2.jarxmlbeans-2.4.0.jarxmlschema-core-2.0.jarxmlsec-1.4.5.jarxmltooling-1.3.1.jarxsdlib-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         //獲得服務工廠bean19         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         //啟動服務-----publish27         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 zhaoqx14  *15  */16 @WebService17 //將服務端改成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 }

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.