Spring整合Apache CXF

首先导入spring和cxf相关的jar包到web工程中

 

1. 新建接口WSUserService

import javax.jws.WebService;

@WebService
public interface WSUserService {
	String getUserInfo(String userCode);
}

2. 创建实现类WSUserServiceImpl

public class WSUserServiceImpl implements WSUserService {

	public String getUserInfo(String userCode) {
		return "用户代码是: " + userCode;
	}
}

3. 创建applicationContext-cxf-service.xml




	
	
	
	

4. web.xml配置



	
		contextConfigLocation
		classpath:applicationContext-cxf-service.xml
	
	
	
	
		org.springframework.web.context.ContextLoaderListener
	
	
	
	
		CXFServlet
		CXF Servlet
		
			org.apache.cxf.transport.servlet.CXFServlet
		
		1
	
	
		CXFServlet
		/*
	

5. 创建客户端配置applicationContext-cxf-client.xml



	
	
 


 

6. 编写客户端调用程序

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.ckwl.soft.cxf.user.WSUserService;

public class WSUserClient {
	public static void main(String[] args){
		String[] configLocations = new String[]{"classpath:applicationContext-cxf-client.xml"}; 
		ApplicationContext ctx = new ClassPathXmlApplicationContext(configLocations);
		WSUserService userWSClient = (WSUserService)ctx.getBean("userWSClient");
		String result = userWSClient.getUserInfo("09037948");
		System.out.println(result);
	}
}

启动服务,执行客户端调用程序,控制台输出:

信息: Creating Service {http://user.cxf.soft.ckwl.com/}WSUserServiceService from class com.ckwl.soft.cxf.user.WSUserService
用户代码是: 09037948




 

你可能感兴趣的:(spring,spring,cxf)