webservice--cxf和spring结合
服务端:
实体:
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结合的更多相关文章
- WebService—CXF整合Spring实现接口发布和调用过程
一.CXF整合Spring实现接口发布 发布过程如下: 1.引入jar包(基于maven管理) <!-- cxf --> <dependency> <groupId> ...
- CXF集成Spring实现webservice的发布与请求
CXF集成Spring实现webservice的发布(服务端) 目录结构: 主要代码: package com.cxf.spring.pojo; public class User { int id ...
- webservice 服务端例子+客户端例子+CXF整合spring服务端测试+生成wsdl文件 +cxf客户端代码自动生成
首先到CXF官网及spring官网下载相关jar架包,这个不多说.webservice是干嘛用的也不多说. 入门例子 模拟新增一个用户,并返回新增结果,成功还是失败. 大概的目录如上,很简单. Res ...
- CXF整合Spring发布WebService实例
一.说明: 上一篇简单介绍了CXF以及如何使用CXF来发布一个简单的WebService服务,并且介绍了客户端的调用. 这一篇介绍如何使用CXF与spring在Web项目中来发布WebService服 ...
- 使用CXF与Spring集成实现RESTFul WebService
以下引用与网络中!!! 一种软件架构风格,设计风格而不是标准,只是提供了一组设计原则和约束条件.它主要用于客户端和服务器交互类的软件.基于这个风格设计的软件可以更简洁,更有层次,更易于实现缓存 ...
- CXF整合Spring开发WebService
刚开始学webservice时就听说了cxf,一直没有尝试过,这两天试了一下,还不错,总结如下: 要使用cxf当然是要先去apache下载cxf,下载完成之后,先要配置环境变量,有以下三步: 1.打开 ...
- 在web项目中使用cxf开发webservice,包含spring支持
本文主要介绍了,如何使用cxf内置的例子,学会开发webserivce,在web项目中使用,且包含spring支持. webserivce的开发可以使用cxf或者axis,好像还有httpclient ...
- 【WebService】WebService之CXF和Spring整合(六)
前面介绍了WebService与CXF的使用,项目中我们经常用到Spring,这里介绍CXF与Spring整合 步骤 1.创建一个Maven Web项目,可以参照:[Maven]Eclipse 使用M ...
- Webservice实践(七)CXF 与Spring结合+tomcat发布
上一节介绍了如何使用CXF 来发布服务,但是没有介绍使用web 容器来发布,很多项目需要用tomcat 这样的容器来发布.另外本节将介绍CXF 与spring 结合的方法. 一 目标: 1.利用spi ...
- 【WebService】——CXF整合Spring
相关博客: [WebService]--入门实例 [WebService]--SOAP.WSDL和UDDI 前言: 之前的几篇博客基本上都是使用jdk来实现WebService的调用,没有使用任何框架 ...
随机推荐
- IDEA升级开源框架
在开发过程中,我们经常会用到一些 GitHub或者Gitee上的开源框架来快速搭建我们的业务系统,但是当框架被我们大批量修改后,开源框架又有升级了.这时候升级框架就变得很麻烦,也不能直接直接进行合并, ...
- Centos7上安装docker (新手版本)
1首先要有一个安装好的Centos7 2打开终端,输入一下命令(自动安装最新版本) curl -fsSL https://get.docker.com | bash -s docker --mirro ...
- 在 macOS 上运行无限许可的 Nessus 10
请访问原文链接:https://sysin.org/blog/nessus-unlimited-on-macos/,查看最新版.原创作品,转载请保留出处. 作者:gc(at)sysin.org,主页: ...
- 在线编辑Word——插入图表
在Word中可插入图表,配合使用表格能够更加全方位的展示数据的可信度并增加数据的可读性.本文将通过使用在线编辑器 Spire.Cloud Word 演示如何来插入图表,并设置相关格式化操作.具体步骤如 ...
- Centos6.8 yum报错及修复YumRepo Error: All mirror URLs are not using ftp, http[s] or file. Eg. Invalid
问题 使用yum安装软件时报错 YumRepo Error: All mirror URLs are not using ftp, http[s] or file. Eg. Invalid relea ...
- redis 内存划分
1.数据:作为数据库,数据是最主要的部分,这部分占用的内存会被统计在used_memory中 2.进程内存:redis主进程本身运行需要占用的内存,这部分内存会被统计在used_memory_rss中 ...
- Hi3516开发笔记(三):Hi3516虚拟机基础环境搭建之交叉编译环境境搭建以及开机启动脚本分析
前言 前面进行了可以传输,那么写一个简单的C程序来交叉编译并传入运行. 虚拟机 上一篇搭建的虚拟机环境,包含了sftp传递文件,网络能ping通,基于上一篇的虚拟机继续搭建. 海思交叉 ...
- rm命令弱爆了!
大家好,我是良许. 创建.删除和修改文件是用户在 Linux 系统中执行的非常常见操作.大家都知道,在 Linux 系统里使用 rm 命令删除单个文件时,几乎一瞬间就完成了.但是如果文件数量很大,那么 ...
- 使用apt安装docker
使用apt安装docker # 更新数据源 apt-get update # 安装所需依赖 apt-get -y install apt-transport-https ca-certificates ...
- Hive处理Json数据
Json 格式的数据处理 Json 数据格式是我们比较常用的的一种数据格式,例如埋点数据.业务端的数据.前后端调用都采用的是这种数据格式,所以我们很有必要学习一下这种数据格式的处理方法 准备数据 ca ...