javaweb学习路之四--cxf发布Webservice
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javaweb学习路之四--cxf发布Webservice,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3423字,纯文字阅读大概需要5分钟。
内容图文
背景:maven构建的springMvc+mybatis框架
源码---》https://github.com/Zering/MyWeb
步骤:(本步骤是自己在实际探索过程中的步骤,我的思路是先简单粗暴的写出方法,报错了再根据错误来解决问题)
第一步:直接写出了接口和实现类
示例接口代码
package com.app.service; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; @WebService @SOAPBinding(style = Style.RPC) public interface IWebService { public String sayHello(String string); }
示例实现类方法
package com.app.service.impl; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.jws.soap.SOAPBinding.Style; import org.springframework.stereotype.Service; import com.app.service.IWebService; @Service @WebService(endpointInterface="com.app.service.IWebService",serviceName="webservice1") @SOAPBinding(style = Style.RPC) public class WebserviceImpl implements IWebService { @Override public String sayHello(String string) { return "hello "+string; } }
第二步:写cxf的配置信息,创建一个application-cxf.xml包含如下信息:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd" default-autowire="byName"> <import resource="classpath*:META-INF/cxf/cxf.xml" /> <import resource="classpath*:META-INF/cxf/cxf-extension-soap.xml" /> <import resource="classpath*:META-INF/cxf/cxf-servlet.xml" /> <bean id="inMessageInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"/> <bean id="outLoggingInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/> <jaxws:endpoint implementor="com.app.service.impl.WebserviceImpl" address="/webservice1"></jaxws:endpoint> </beans>
注意:这个文件里面的三个<import>是从jar包中导入的,所以在classpath后面一定要加*号
步骤三:修改web.xml
1.修改<context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mybatis.xml classpath:application-cxf.xml</param-value>
</context-param>
2.追加一个webservice的servelet
<!-- For WebService --> <servlet> <servlet-name>CXFServlet</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFServlet</servlet-name> <url-pattern>/WebService/*</url-pattern> </servlet-mapping>
步骤四:这个时候启动tomcat的话,会有异常说缺啥缺啥的,根据这个信息来导入相应的jar包,加的jar包如下:
<dependency> <groupId>org.apache.cxf</groupId> <artifactId>apache-cxf</artifactId> <version>3.1.6</version> <type>pom</type> </dependency> <dependency>
<groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-bindings-soap</artifactId> <version>3.1.6</version> </dependency>
步骤五:验证,启动tomcat,url输入 http://localhost:8080/MyWeb/WebService
完成。
原文:http://www.cnblogs.com/zhanghj405/p/5626310.html
内容总结
以上是互联网集市为您收集整理的javaweb学习路之四--cxf发布Webservice全部内容,希望文章能够帮你解决javaweb学习路之四--cxf发布Webservice所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。