通过CXF +spring 完成对webservice服务端搭建

webservice 服务端搭建,可以通过直接创建webservice项目,也可以在普通项目中搭建,本人感觉搭建主要在配置、类代码跟普通代码无太大区别

import java.util.ArrayList;
import java.util.List;
import javax.jws.WebService;
import com.cpp.procurement.projectregister.pojo.GEMForGBESExpertInfoVo;
@WebService(endpointInterface="com.procurement.projectregister.service.IWebserviceTest")
public class WebserviceTest implements IWebserviceTest{

	/**
	 * 业务逻辑的处理(测试时实用)
	 */
	@Override 
	public List<GEMForGBESExpertInfoVo> GetExpertInfoList(String message) {
		GEMForGBESExpertInfoVo bean = new GEMForGBESExpertInfoVo();
		bean.setIdCard("11111");
		bean.setName("22222");
		bean.setPhone("3333333");
		List<GEMForGBESExpertInfoVo> expertInfoVos = new ArrayList<GEMForGBESExpertInfoVo>();
		expertInfoVos.add(bean);
		return expertInfoVos;
	}	
}


接口类:

import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface IWebserviceTest {
	@WebMethod
	public List<GEMForGBESExpertInfoVo> GetExpertInfoList(String message);
}


实体类

public class GEMForGBESExpertInfoVo {

	/**
	 * 专家身份证号
	 */
	private String idCard;
	/**
	 * 专家名称
	 */
	private String name;
	/**
	 * 电话
	 */
	private String phone;
	
	public String getIdCard() {
		return idCard;
	}
	public void setIdCard(String idCard) {
		this.idCard = idCard;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}


特别主意:声明属性时一定要私有,使用private ,使用public启动服务时,一直抛异常,说srping 无法service类进行加载,找不到实体类的属性

spring 中xml的配置

在testservice完成了对实体类vo的注入

<?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:p="http://www.springframework.org/schema/p" 
	xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
						http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.0.xsd
	 					http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
	<import resource="classpath:META-INF/cxf/cxf.xml" />  
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />  
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> 
	
	<bean id="GEMForGBESExpertInfoVo" class="com.procurement.projectregister.pojo.GEMForGBESExpertInfoVo"/>
	<jaxws:endpoint id="testService" implementorClass="com.procurement.projectregister.service.WebserviceTest" address="/test-service" >
		<jaxws:implementor ref="GEMForGBESExpertInfoVo">
		</jaxws:implementor>
	</jaxws:endpoint>	
</beans>

 

Spring applicationContext.xml 中引入上述业务xml,也可以直接将上述xml内容写入到spring applicationContext.xml中

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 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-2.0.xsd"
	default-lazy-init="false">
	<import resource="classpath:com/procurement/projectregister/spring-webservice-test.xml"/>
</beans>

 

web.xml 配置

webservice地址请求时,是webservcie拦截、由cxf进行处理

<servlet>
		<servlet-name>cxf</servlet-name>
		<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
		</servlet>	
<servlet>
<servlet-mapping>
		<servlet-name>cxf</servlet-name>
		<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>

最后进行部署、地址访问

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值