Webservice服务发布-Spring框架

 在上两篇文章中我们讲了Webservice的服务提供端和服务调用端,但是接下来怎么在项目中使用呢?学以致用才是我们学习的最终目的。学习前提:大家在学习这篇文章时需要有Spring框架和Maven构建工具的使用经验(项目中Spring的配置、Maven工具的使用不再讲述)。

环境准备:

Windows7

JDK7

Eclipse4.4.2

Maven

Spring4


在Eclipse中创建一个Maven项目,项目名称为:oaproj


1、在pom.xml中引入WebService相关的jar依赖

<!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-frontend-jaxws -->
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxws</artifactId>
    <version>3.1.6</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-transports-http -->
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http</artifactId>
    <version>3.1.6</version>
</dependency>

2、在web.xml加载启动Webservice


<servlet>  
        <servlet-name>cxf</servlet-name>  
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>  
        <load-on-startup>1</load-on-startup>  
    </servlet>  
    <servlet-mapping>  
        <servlet-name>cxf</servlet-name>  
        <url-pattern>/services/*</url-pattern>  
    </servlet-mapping> 


3、创建WebService相关的Spring配置文件:spring-webservie.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"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
    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
        http://cxf.apache.org/transports/http/configuration      
        http://cxf.apache.org/schemas/configuration/http-conf.xsd">

    <bean id="userServiceImpl" class="cn.com.webservice.user.UserServiceImpl" />

    <jaxws:endpoint id="userServiceImplService" address="/user"
        implementor="#userServiceImpl">
    </jaxws:endpoint>


</beans>

4、把服务端代码迁移到项目的\src\main\java\cn\com\webservice\user,如下图:


注释:

(1)迁入到框架中后\src\main\java\cn\com\webservice\user路径下的类StartServer.java已经没用可以删除,服务的创建及启动在第3步中进行

(2)把\src\main\java\cn\com\webservice\user\UserServiceImpl.java类的endpointInterface="cn.com.UserService"修改为endpointInterface="cn.com.webservice.user.UserService"

5、启动oaproj项目,并在浏览器中访问地址:http://127.0.0.1:8080/oaproj/services/user?wsdl,成功则如下图:









  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值