Spring3整合cxf2.7.10

初学CXF,参考官方的文档对Spring3和CXF2.7.10做了一个整合,记录下来以备忘。


一、Spring用到的到包:

Spring3整合cxf2.7.10_第1张图片

二、CXF用到的包:


三、工程示例

Spring3整合cxf2.7.10_第2张图片


四、Web.xml文档




	 	
	   
      
        CXFService  
        org.apache.cxf.transport.servlet.CXFServlet  
        1  
      
      
        CXFService  
        /CXFService/*  
     
		
		
	
		contextConfigLocation
		/WEB-INF/applicationContext.xml 
	
	
		org.springframework.web.context.ContextLoaderListener
	



五、applicationContext.xml文档




    

	
	
	
	

	
	



六、WebService接口示例

package com.lee.server;

import java.util.List;
import java.util.Map;

import javax.jws.WebService;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import com.lee.model.Cat;
import com.lee.model.User;
import com.lee.tools.FkXmlAdapter;

@WebService
public interface ServiceHello {
	
	public String say(String name);
	
	public List getCatByUser(User user);
	
	/**
	 * CXF无法处理Map,于是用FkXmlAdapter.calss处理
	 * @return
	 */
	@XmlJavaTypeAdapter(FkXmlAdapter.class)
	public Map getAllCat();
	public String hehe();
}



七、接口实现类示例

package com.lee.server.impl;

import java.util.List;
import java.util.Map;

import javax.jws.WebService;


import com.lee.model.Cat;
import com.lee.model.User;
import com.lee.server.ServiceHello;
import com.lee.server.UserService;

@WebService(endpointInterface="com.lee.server.ServiceHello")
public class ServiceHelloImpl implements ServiceHello{

	@Override
	public String say(String name) {
		// TODO Auto-generated method stub
		return name+"你好!";
	}

	@Override
	public List getCatByUser(User user) {
		// TODO Auto-generated method stub
		UserService us = new UserServiceImpl();
		return us.getCatByUser(user);
	}

	@Override
	public Map getAllCat() {
		// TODO Auto-generated method stub
		UserService us = new UserServiceImpl();
		return us.getAllCat();
	}
	
	@Override
	public String hehe(){
		return "hhe";
	}
	
	
}

八、在Tomcat中运行,浏览器中输入:http://127.0.0.1/WS_EE/CXFService/HelloWorld?wsdl 

Spring3整合cxf2.7.10_第3张图片


PS: 在URL中WS_EE为工程名,CXFService为Web.xml中配置的路径,HelloWorld为applicationContext.xml中的address="/HelloWorld"。

示例源码下载地址:http://download.csdn.net/detail/libinsbox/6949443

你可能感兴趣的:(CXF)