maven下spring整合cxf

在做spring整合cxf的时候遇到了很多问题,困扰了好久,还好网上有很多资料能够帮助我解决这些问题,下面我把我的整合过程和大家分享一下,我主要在前期环境方面多说一些,因为在上面浪费了很多时间,报了很多错,不多说我就直接上图了

第一步  创建一个web工程

maven下spring整合cxf_第1张图片

 第二步 点击项目右键属性,Project Facets 将项目转换成web工程并选择tomcat后提交

maven下spring整合cxf_第2张图片

 第三步 加入自己使用jdk

maven下spring整合cxf_第3张图片

 第四步 使用maven导入需要的jar包

jar包地址我就不复制了,请原谅,因我都是把相关jar包都导入了,也没有简化有用的,基本spring和cxf的jar包都导入了,

第五步 创建配置文件

第1小步首先是web.xml文件


 xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    
   
        contextConfigLocation
        
        classpath*:/config/applicationContext-webservice.xml
        

    

    
        
             
            org.springframework.web.context.ContextLoaderListener     
   
    
   

      
         
       CXFServlet   
                  
               org.apache.cxf.transport.servlet.CXFServlet    
         
     
          1      
       
   
            
             CXFServlet  
             /webservice/*  
       

    

第2小步cxf配置文件


    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
        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://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
 
             implementor="com.sshome.ssmcxf.webservice.impl.SsWebServiceImpl" />

第3小步编写实体类 (先看下我的项目结构吧)

maven下spring整合cxf_第4张图片

 User类

package com.sshome.ssmcxf.entity;

public class User {
    
    private int id;
    private String userName;
    private String password;

    public User() {
        super();
    }

    public int getId() {
        return id;
    }

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

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Override
    public String toString() {
        return "User [id=" + id + ", userName=" + userName + ", password="
                + password + "]";
    }
    
}

SsWebService 类

package com.sshome.ssmcxf.webservice;

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

@WebService
public interface SsWebService {
    
    public String getUser(@WebParam(name="userName") String userName,@WebParam(name="password") String password);
    
}

SsWebServiceImpl类

package com.sshome.ssmcxf.webservice.impl;

import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sshome.ssmcxf.webservice.SsWebService;
@Transactional
@Service
@WebService(endpointInterface = "com.sshome.ssmcxf.webservice.SsWebService", serviceName = "SsWebService")
public class SsWebServiceImpl implements SsWebService {

    @Override
    public String getUser(String userName, String password) {
        return null;
    }

}

最后将项目部署到tomcat上面

maven下spring整合cxf_第5张图片

 

注意红箭头是项目名,黑箭头是web.xml配置的映射路径,灰箭头是cxf配置文件的address对应名+?wsdl是官方规定的

ok 结束

你可能感兴趣的:(maven下spring整合cxf)