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);
}
}