ssm+cxf笔记

初学随记,感觉spring与cxf不会太过耦合,使用的是spring的注入特性而已,所以配置文件可以分开。
1. 先创建接口类和接口实现类

@WebService
@SOAPBinding(style = Style.RPC)
public interface RXFService {
    public String getText(@WebParam(name = "s") String[] s);
}

@Service
public class RXFServiceImpl implements RXFService {
    @Override
    public String getText(String[] s) {
        int len = s.length;
        String ss = new String();
        if(len>0&&len%2==0)
        {
            for(int i=0;i<len;i+=2)
            {
                ss += "<"+s[i]+">";
                ss += s[i+1];
                ss += "</"+s[i]+">";
            }
            return ss;
        }
        return "change not success";
    }
}

注意:接口的@WebService是cxf需要的,而实现类的@Service是springmvc框架的注解

2.新建cxf.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:util="http://www.springframework.org/schema/util" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xmlns:soap="http://cxf.apache.org/bindings/soap"
    xmlns:jaxrs="http://cxf.apache.org/jaxrs" 
    xsi:schemaLocation="
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/jdbc
    http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
    http://www.springframework.org/schema/cache
    http://www.springframework.org/schema/cache/spring-cache.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop.xsd
    http://www.springframework.org/schema/util
    http://www.springframework.org/schema/util/spring-util.xsd
    http://cxf.apache.org/bindings/soap 
    http://cxf.apache.org/schemas/configuration/soap.xsd 
    http://cxf.apache.org/jaxws 
    http://cxf.apache.org/schemas/jaxws.xsd
    http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.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" /> 
      <!-- <jaxws:server id="eoo" serviceClass="com.picc.easyorder.service.RXFService" address="/eoo"></jaxws:server>  -->


      <!-- 配置方式1,在impl的@Service(“RXFService”) 里面添加名称,利用spring的注入实现-->      
      <jaxws:endpoint id="eoo" 
        implementor="#RXFService" 
        address="/eoo" /> 

    <!-- <jaxws:server serviceClass="com.picc.easyorder.service.RXFService" address="/eoo"></jaxws:server> -->

     <!-- 配置2,直接在此配置文件中绑定--> 
    <!-- <jaxws:server id="eoo" serviceClass="com.picc.easyorder.service.RXFService" serviceName="hiWS" address="/eoo"> 
<jaxws:serviceBean> 
      <bean class="com.picc.easyorder.service.impl.RXFServiceImpl" ></bean> 
</jaxws:serviceBean>    
</jaxws:server> -->
</beans>

3.web.xml的配置
在最后加入

<!-- cxf服务启动servlet -->
    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
        <init-param>  
            <param-name>config-location</param-name>  
            <param-value>classpath:conf/cxf.xml</param-value>  <!-- cxf.xml在conf包下  -->
        </init-param> 
    </servlet>
    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/cxf/*</url-pattern>
    </servlet-mapping>

测试在浏览器输入localhost:8080/工程名/在web.xml设置的url(此为cxf)/于cxf.xml配置的address
如果后台报错org.apache.cxf.interceptor.Fault: No such operation则在url后加入?wsdl,如http://localhost:8080/testWebService/cxf?wsdl,若还报错,则检查是否接口类与实现类没绑定成功,检查配置文件。
最后附一个spring+cxf的小demo:http://download.youkuaiyun.com/detail/lin245709189/9892017

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lin245709189

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值