CXF + Spring 发布 SOAP服务

web工程目录如下: 

实体类com.cc.entity.User如下:

package com.cc.entity;

import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;


@XmlRootElement
public class User implements Serializable{
    private int id;
    private String name;
    private String telephone;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }
}

发布SOAP服务com.cc.service.UserService:

package com.cc.service;

import com.cc.entity.User;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
 * Created by CHENLIN on 2016/3/11.
 */
@WebService(name = "InvokeService", targetNamespace = "http://impl.service.cc.com")
public interface UserService {
    @WebMethod(operationName = "getName", action = "urn:GetName")
    public User getName(@WebParam(name="userName") String userName);
}

UserService接口实现com.cc.service.impl:

package com.cc.service.impl;

import com.cc.entity.User;
import com.cc.service.UserService;


public class UserServiceImpl implements UserService{

    @Override
    public User getName(String userName) {
        User user = new User();
        user.setId(1);
        user.setName(userName);
        user.setTelephone("111"+userName);
        return user;
    }
}

Spring的入口文件web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
    <!-- 配置Spring的配置文件 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/bean.xml</param-value>
    </context-param>

    <!-- 配置Spring的web Context监听器,将Spring与web工程集成在一起 -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <!-- 配置CXF -->
    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <display-name>CXF Servlet</display-name>
        <servlet-class>
            org.apache.cxf.transport.servlet.CXFServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <!-- 使用CXF发布服务 -->
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/service/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

配置需要暴露的SOAP服务的bean:

<?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">

       <!--配置需要暴露的SOAP服务的bean-->
       <jaxws:endpoint id="userServiceImplBean" address="/userSerivce"
               implementor="com.cc.service.impl.UserServiceImpl"></jaxws:endpoint>

</beans>

启动tomcat,查看发布的SOAP服务:

其中有几点需要注意:服务发布接口UserService中的命名是一一对应的:(注解@WebParam用于表示SOAP服务的参数名) 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值