700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > cxf发布 webservice服务

cxf发布 webservice服务

时间:2023-12-24 16:51:09

相关推荐

cxf发布 webservice服务

导包

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-0108.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.v0725.jarjetty-http-7.4.5.v0725.jarjetty-io-7.4.5.v0725.jarjetty-security-7.4.5.v0725.jarjetty-server-7.4.5.v0725.jarjetty-util-7.4.5.v0725.jarjoda-time-1.6.2.jarjra-1.0-alpha-4.jarjs-1.7R2.jarjsr311-api-1.1.1.jarmsv-core-.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-.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 {1112public String sayHello(String name){13 System.out.println("sayHello called...");14 return "hello " + name;15}1617public 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 {20public String sayHi(String name){21 System.out.println("sayHi called...");22 return "hi " + name;23}2425public 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 }

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。