Service

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style; @WebService(targetNamespace="http://tempuri.org/")
@SOAPBinding(style=Style.DOCUMENT)
public interface MyService { @WebMethod
String sayHiTo(String name); @WebResult(name="sayHelloResult")
String sayHello(@WebParam(name="name")String name); }

Service Impl

import javax.annotation.Resource;
import javax.jws.WebService;
import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;
import javax.xml.ws.handler.soap.SOAPMessageContext; @WebService(serviceName = "myService", targetNamespace = "http://tempuri.org/", endpointInterface = "cn.config.MyService")
public class MyServiceImpl implements MyService { @Override
public String sayHiTo(String name) {
return name;
} @Resource
private WebServiceContext wsc; @Override
public String sayHello(String name) {
MessageContext ctx = wsc.getMessageContext();
HttpServletRequest request = (HttpServletRequest) ctx.get(SOAPMessageContext.SERVLET_REQUEST);
return request.getContentType();
} }

javaBean Configuration

import org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter;

@Configuration
public class WebServiceConfig { @Bean
public SimpleJaxWsServiceExporter simpleJaxWsServiceExporter() {
SimpleJaxWsServiceExporter sjaxWsServiceExporter = new SimpleJaxWsServiceExporter();
sjaxWsServiceExporter.setBaseAddress("http://localhost:8081/services/");
return sjaxWsServiceExporter;
} @Bean
public MyServiceImpl myServiceImpl() {
return new MyServiceImpl();
} }

服务器:tomcat 端口号:8081
wsdl:http://localhost:8081/services/helloservice?wsdl

说明及注意

(1)、通过http://localhost:8081/services/myService?wsdl 访问webservice部署描述符 
还有自动生成的xsd:http://localhost:8081/services/myService?xsd=1 。
(2)、@SOAPBinding(parameterStyle=ParameterStyle.WRAPPED)
必须添加,否则会报错;另外,如果发布的方法只有一个参数可以使用@SOAPBinding(parameterStyle=ParameterStyle.BARE)。
(3)、@WebService(serviceName = "myService") 服务名称与Spring配置的bean一致。
(4)、webservice的端口设置不要与服务器一样,这一点非常重要否则服务器应用与webservice服务冲突会产生HTTP404错误。

spring 发布 Jax-Ws Service (二)的更多相关文章

  1. idea+maven+spring+cxf创建webservice应用(二)生成客户端程序

    idea+maven+spring+cxf创建webservice应用(二)生成客户端程序,以上一篇为基础"idea+maven+spring+cxf创建webservice应用" ...

  2. 解决cxf+spring发布的webservice,types,portType和message以import方式导入

    用cxf+spring发布了webservice,发现生成的wsdl的types,message和portType都以import的方式导入的.. 原因:命名空间问题 我想要生成的wsdl在同个文件中 ...

  3. 构建一个基于 Spring 的 RESTful Web Service

    本文详细介绍了基于Spring创建一个“hello world” RESTful web service工程的步骤. 目标 构建一个service,接收如下HTTP GET请求: http://loc ...

  4. spring事务详解(二)简单样例

    系列目录 spring事务详解(一)初探事务 spring事务详解(二)简单样例 spring事务详解(三)源码详解 spring事务详解(四)测试验证 spring事务详解(五)总结提高 一.引子 ...

  5. 使用Apache CXF和Spring集成创建Web Service(zz)

    使用Apache CXF和Spring集成创建Web Service 您的评价:       还行  收藏该经验       1.创建HelloWorld 接口类 查看源码 打印? 1 package ...

  6. 使用CXF+Spring发布WebService,启动报错

    使用CXF+Spring发布WebService,启动报错,日志如下: 五月 12, 2017 9:01:37 下午 org.apache.tomcat.util.digester.SetProper ...

  7. Spring框架学习之IOC(二)

    Spring框架学习之IOC(二) 接着上一篇的内容,下面开始IOC基于注解装配相关的内容 在 classpath 中扫描组件 <context:component-scan> 特定组件包 ...

  8. 【Java Web开发学习】Spring发布RMI服务

    [Java 远程服务]Spring发布RMI服务 转载:https://www.cnblogs.com/yangchongxing/p/9084066.html RmiServiceExporter可 ...

  9. spring cloud微服务实践二

    在上一篇,我们已经搭建了spring cloud微服务中的注册中心.但只有一个注册中心还远远不够. 接下来我们就来尝试提供服务. 注:这一个系列的开发环境版本为 java1.8, spring boo ...

  10. Spring事务原理分析-部分二

    Spring事务原理分析-部分二 说明:这是我在蚂蚁课堂学习了余老师Spring手写框架的课程的一些笔记,部分代码代码会用到余老师的课件代码.这不是广告,是我听了之后觉得很好. 课堂链接:Spring ...

随机推荐

  1. ajax成功返回数据中存在多余字符的处理

    ajax里有需要判断反馈的字符串是否为“ok”,在浏览器里调试,看到返回的内容明明是“ok”,但是if(“ok”==data)判断为false,用alert打印内容也是ok,但是打印长度的时候却是3. ...

  2. 数学图形(2.23)Cylindric sine wave柱面正弦曲线

    柱面正弦曲线 #http://www.mathcurve.com/courbes3d/couronnetangentoidale/couronnetangentoidale.shtml vertice ...

  3. C#视频播放器【转】

    1对于视频播放器来说,最重要的功能,莫过于播放视频文件了这就要用到VS自带的控件——Windows Media Player windows media player 将Windows Media P ...

  4. 使用BeyondCompare比较文件夹下的文件时,相同的文件内容,但显示为不相同

    主要原因是: 两个文件行尾标题不一致而导致的,一个是PC,一个是Unix 解决办法: 随便比较文件夹中的两个文件,点击规则,去掉比较行尾(pc/mac/unix)选项,点击确认,回到文件夹比较界面,刷 ...

  5. 【树莓派】Linux 系统级别代理配置

    在Windows下,通过代理服务器怎么去设置连接代理服务器,浏览器---->工具------>internet选项----->连接--->局域网设置------->勾选“ ...

  6. QtGui.QCalendarWidget

    A QtGui.QCalendarWidget provides a monthly based calendar widget. It allows a user to select a date ...

  7. QtGui.QFileDialog

    The QtGui.QFileDialog is a dialog that allows users to select files or directories. The files can be ...

  8. 指定安装应用程序移至SD卡(App2SD)

    在2.2发布之后,除了增加Flash Player的支持外,最令人瞩目的莫过于App to Sdcard的支持了.至此之前,android应用程序仅能安装于手机内存,而在“有限”的资源下,至多能安装5 ...

  9. linux 挂载 ISO 文件

    sudo sudo mount -o loop SUSE-Linux-10.1-GM-DVD-x86_64.iso /media/cdrom/ sudo umount /media/cdrom

  10. python标准库 正则表达式(re包)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 正则表达式(regular expression)主要功能是从字符串(string)中通过特定的模式(pattern) ...