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的调用,没有使用任何框架 ...
随机推荐
- centos安装pm2报错
报错信息: /usr/lib/node_modules/pm2/node_modules/chalk/source/index.js:103 ...styles, 这个问题其实很简单,就是npm和no ...
- js分支语句
一.逻辑分支(选择结构,分支结构) 其实今天的课程才算开始涉及到逻辑 程序的三大结构 顺序结构 - 每天 代码逐行执行,一行一行自上而下执行 分支结构 有选择了,十字路口的选择,只能选择一个,如果.. ...
- 访问kubernetes CRD的几种方式
访问kubernetes CRD的几种方式 最近在使用代码操作VictoriaMetrics Operator的CRD资源的过程中,探究了集中访问CRD资源的方式.下面以VictoriaMetrics ...
- 第四周PTA笔记 好吃的巧克力+特殊的翻译+下次一定(续)+走迷宫
好吃的巧克力 超市正在特价售卖巧克力,正好被贪吃的Lucky_dog看见了. 巧克力从左到右排成一排,一共有N个,M种. 超市有一个很奇怪的规定,就是你在购买巧克力时必须提供两个数字a和b,代表你要购 ...
- 如何实现异步 connect
写过网络程序的同学,应该都知道 connect 函数,在 socket 开始读写操作之前,先要进行连接,也即 TCP 的三次握手 , 这个过程就是在 connect 函数中完成的, connect 函 ...
- Go语言核心36讲(Go语言实战与应用五)--学习笔记
27 | 条件变量sync.Cond (上) 前导内容:条件变量与互斥锁 我们常常会把条件变量这个同步工具拿来与互斥锁一起讨论.实际上,条件变量是基于互斥锁的,它必须有互斥锁的支撑才能发挥作用. 条件 ...
- 力扣 - 剑指 Offer 22. 链表中倒数第k个节点
题目 剑指 Offer 22. 链表中倒数第k个节点 思路1(栈) 既然要倒数第k个节点,那我们直接把所有节点放到栈(先进后出)里面,然后pop弹出k个元素就可以了 代码 class Solution ...
- 跟着老猫来搞GO-内建容器Map
前期回顾 在上面的文章中,老猫和大家分享了GO语言中比较重要的两种数据结构,一种是数组,另外一种是基于数组的slice.本篇文章想要继续和大家分享剩下的容器以及字符字符串的处理. MAP map的定义 ...
- Redis | 第4章 Redis中的数据库《Redis设计与实现》
目录 前言 1. Redis中的数据库 2. 数据库的键空间 3. 键的生成时间与过期时间 4. Redis中的过期键删除策略 5. AOF.RDB和复制功能对过期键的处理 5.1 生成 RDB 文件 ...
- asList和subList的缺陷
概述 在开发中我们经常使用asList去把一个数组转换为List.也存在通过subList.subMap.来对List.Map.Set来进行类似使用subString方法来对String对象进行分割处 ...