spring整合webservice配置学习总结

webservice依赖

<dependency>
	<groupId>org.apache.cxf</groupId>		
	<artifactId>cxf-rt-frontend-jaxws</artifactId>
	<version>3.1.10</version>
</dependency>
<dependency>
	<groupId>org.apache.cxf</groupId>		
	<artifactId>cxf-rt-transports-http</artifactId>
	<version>3.1.10</version>
</dependency>

发布服务的配置[服务端]

<?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:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://cxf.apache.org/jaxws
		http://cxf.apache.org/schemas/jaxws.xsd
		">
	<bean id="waybillWs" class="pdsu.xps.redsun.bos.ws.impl.WaybillWs">
		<property name="waybillBiz" ref="waybillBiz"></property>
		<property name="waybilldetailBiz" ref="waybilldetailBiz"></property>
	</bean>
	<!-- 发布cxf服务 -->
	<jaxws:server address="/waybill">
		<jaxws:serviceBean>
			<ref bean="waybillWs" />
		</jaxws:serviceBean>
	</jaxws:server>
</beans>	

代码编写注意

// 接口上需要写上webservice注解
import javax.jws.WebService;
@WebService
public interface IWaybillWs {}

接收服务的配置[客户端]

<?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:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://cxf.apache.org/jaxws
		http://cxf.apache.org/schemas/jaxws.xsd
		">
	<!-- 接收cxf服务serviceClass: 是接口 -->
	<jaxws:client id="waybillClient"
		address="http://localhost:9090/redsun/ws/waybill?wsdl"
		serviceClass="pdsu.xps.redsun.bos.ws.impl.IWaybillWs">
	</jaxws:client>
</beans>

代码编写注意

获取webservice代码

下为需要将服务端使用的webserice的代码放置的位置
在这里插入图片描述
代码生成的步骤
在这里插入图片描述


 1. wsimport:在jdk的bin目录下
 2. -encoding utf-8:设置生成的代码为utf-8编码
 3. -s:生成源码
 4. ".":当前目录
 5. http://localhost:9090/redsun/ws/waybill?wsdl:服务的位置,服务必须开启
代码的使用

直接声明代码中的类即可使用其内置方法
下面使用属性注入方法

// 接口
public interface IOrdersBiz extends IBaseBiz<Orders>{
	List<Waybilldetail> waybilldetailList(Long sn);
}
// 实现类
public class OrdersBiz extends BaseBiz<Orders> implements IOrdersBiz {
	private IWaybillWs waybillWs;
	public void setWaybillWs(IWaybillWs waybillWs) {
		this.waybillWs = waybillWs;
	}
	public List<Waybilldetail> waybilldetailList(Long sn) {
		// waybilldetailList(sn): 是服务端的方法
		return waybillWs.waybilldetailList(sn);
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值