服务端:

实体:

package entity;

import java.util.Date;

/**
* 实体
*/
public class Pojo {
//温度
private String detail;
//日期
private Date date;
//最高
private int temperature_max;
//最低
private int temperature_min;
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public int getTemperature_max() {
return temperature_max;
}
public void setTemperature_max(int temperature_max) {
this.temperature_max = temperature_max;
}
public int getTemperature_min() {
return temperature_min;
}
public void setTemperature_min(int temperature_min) {
this.temperature_min = temperature_min;
} }

SEI:

package service;

import java.util.List;

import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService; import entity.Pojo; /**
* 接口
*/
@WebService(serviceName="PojoService",
portName="PojoPort",
name="PojoPortType",
targetNamespace="http//:Pojo"
)
public interface WeatherInterface { public @WebResult(name="result")List<Pojo> queryWeather(@WebParam(name="cityName")String cityName); }

实现类:

package service;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List; import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService; import com.sun.org.glassfish.gmbal.ParameterNames; import entity.Pojo; /**
* 实现类
*/ public class Impl implements WeatherInterface { @Override
public List<Pojo> queryWeather(String cityName) { List<Pojo> list = new ArrayList<Pojo>(); //日历附件
Calendar calendar = Calendar.getInstance();
int day = calendar.get(Calendar.DATE); Pojo pojo1 = new Pojo();
pojo1.setDetail("晴1");
pojo1.setDate(new Date());
pojo1.setTemperature_max(5);
pojo1.setTemperature_min(-6); Pojo pojo2 = new Pojo();
pojo2.setDetail("晴2");
calendar.set(Calendar.DATE, day+1);
pojo2.setDate(calendar.getTime());
pojo2.setTemperature_max(5);
pojo2.setTemperature_min(-6); Pojo pojo3 = new Pojo();
pojo3.setDetail("晴3");
calendar.set(Calendar.DATE, day+2);
pojo3.setDate(calendar.getTime());
pojo3.setTemperature_max(5);
pojo3.setTemperature_min(-6); list.add(pojo1);
list.add(pojo2);
list.add(pojo3); return list;
} }

spring配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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"> <!-- service -->
<bean id="WeatherInterface" class="service.Impl" /> <!-- 通过jaxws:server方式来配置webservice -->
<jaxws:server serviceClass="service.WeatherInterface" address="/weather">
<jaxws:serviceBean>
<ref bean="WeatherInterface" />
</jaxws:serviceBean>
</jaxws:server>
</beans>

web配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <!-- 加载spring容器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- cxf的servlet -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping> </web-app>

webservice--cxf和spring结合的更多相关文章

  1. WebService—CXF整合Spring实现接口发布和调用过程

    一.CXF整合Spring实现接口发布 发布过程如下: 1.引入jar包(基于maven管理) <!-- cxf --> <dependency> <groupId> ...

  2. CXF集成Spring实现webservice的发布与请求

    CXF集成Spring实现webservice的发布(服务端) 目录结构: 主要代码: package com.cxf.spring.pojo; public class User { int id ...

  3. webservice 服务端例子+客户端例子+CXF整合spring服务端测试+生成wsdl文件 +cxf客户端代码自动生成

    首先到CXF官网及spring官网下载相关jar架包,这个不多说.webservice是干嘛用的也不多说. 入门例子 模拟新增一个用户,并返回新增结果,成功还是失败. 大概的目录如上,很简单. Res ...

  4. CXF整合Spring发布WebService实例

    一.说明: 上一篇简单介绍了CXF以及如何使用CXF来发布一个简单的WebService服务,并且介绍了客户端的调用. 这一篇介绍如何使用CXF与spring在Web项目中来发布WebService服 ...

  5. 使用CXF与Spring集成实现RESTFul WebService

    以下引用与网络中!!!     一种软件架构风格,设计风格而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存 ...

  6. CXF整合Spring开发WebService

    刚开始学webservice时就听说了cxf,一直没有尝试过,这两天试了一下,还不错,总结如下: 要使用cxf当然是要先去apache下载cxf,下载完成之后,先要配置环境变量,有以下三步: 1.打开 ...

  7. 在web项目中使用cxf开发webservice,包含spring支持

    本文主要介绍了,如何使用cxf内置的例子,学会开发webserivce,在web项目中使用,且包含spring支持. webserivce的开发可以使用cxf或者axis,好像还有httpclient ...

  8. 【WebService】WebService之CXF和Spring整合(六)

    前面介绍了WebService与CXF的使用,项目中我们经常用到Spring,这里介绍CXF与Spring整合 步骤 1.创建一个Maven Web项目,可以参照:[Maven]Eclipse 使用M ...

  9. Webservice实践(七)CXF 与Spring结合+tomcat发布

    上一节介绍了如何使用CXF 来发布服务,但是没有介绍使用web 容器来发布,很多项目需要用tomcat 这样的容器来发布.另外本节将介绍CXF 与spring 结合的方法. 一 目标: 1.利用spi ...

  10. 【WebService】——CXF整合Spring

    相关博客: [WebService]--入门实例 [WebService]--SOAP.WSDL和UDDI 前言: 之前的几篇博客基本上都是使用jdk来实现WebService的调用,没有使用任何框架 ...

随机推荐

  1. DeWeb 电脑和手机动态适配

    DeWeb 做多平台适配很方便! 多平台适配代码在OnMouseUp中. X,Y分别表示当前设备的Width/Height: Button : mbLeft : 屏幕纵向, mbRight:屏幕横向: ...

  2. Go语言核心36讲(Go语言进阶技术十三)--学习笔记

    19 | 错误处理(上) 提到 Go 语言中的错误处理,我们其实已经在前面接触过几次了. 比如,我们声明过error类型的变量err,也调用过errors包中的New函数. 我们说过error类型其实 ...

  3. this.$set用法

    this.$set()的主要功能是解决改变数据时未驱动视图的改变的问题,也就是实际数据被改变了,但我们看到的页面并没有变化,这里主要讲this.$set()的用法,如果你遇到类似问题可以尝试下,vue ...

  4. 04 | 函数扩展 | es6

    函数参数的默认值 基本用法 ES6 之前,不能直接为函数的参数指定默认值,只能采用变通的方法. function log(x, y) { y = y || 'World'; console.log(x ...

  5. mysql批量修改某一列的值为另外的值

    sql语句 UPDATE tb_info SET org_id = 2170 WHERE org_id = 815

  6. golang常用库:日志记录库-logrus使用

    介绍 logrus 它是一个结构化.插件化的日志记录库.完全兼容 golang 标准库中的日志模块.它还内置了 2 种日志输出格式 JSONFormatter 和 TextFormatter,来定义输 ...

  7. 【不费脑筋系列】发布个人的代码包到Nuget服务器上,并通过VS引用进行使用的方法

      打打酱油,写点不需要费脑筋的博客先压压惊. 下面讲个关于个人如何开发nuget包,并部署到nuget服务器上的例子.为了保证.net framework和 .net core都可以访问到我的包,我 ...

  8. Git项目迁移(把当前git项目迁移到新的git地址)

    使用 git clone --bare 命令clone当前git git clone --bare http://gitlab.xxx/demo.git 推到新的git地址 cd demo.git g ...

  9. java解析Excel日期格式转换问题

    Excel上传导入,Excel里面单元格是日期的会解析出来数字,比如2020-07-11会解析为44023解决方法一: Excel单元格格式设置为文本格式.解决方法二: 使用代码处理,把解析出来的44 ...

  10. 来了!公开揭密团队成员开发鸿蒙 OpenHarmony 的完整过程(收获官方7000奖金和开发板等,1w字用心总结)

    背景 随着 OpenHarmony 组件开发大赛结果公布,我们的团队成员被告知获得了二等奖,在开心之余也想将我们这段时间宝贵的开发经验写下来与大家分享,当我们看到参赛通知的时候已经是 9 月中旬的时候 ...