spring+cxf编写简单的webservice接口

阅读更多

service接口代码:

package com.gary.test.ws.service;

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

@WebService 
public interface GreetingService { 
   public String greeting(@WebParam(name="userName") String userName); 
} 

 serviceImpl接口实现类代码:

package com.gary.test.ws.service.impl;

import java.util.Calendar;
import com.gary.test.ws.service.GreetingService;

@WebService(endpointInterface = "com.gary.test.ws.service.GreetingService") 
public class GreetingServiceImpl implements GreetingService { 

   public String greeting(String userName){
       return "Hello " + userName + ", currentTime is " + Calendar.getInstance().getTime(); 
   } 
} 

测试代码:

package com.gary.test.ws.test;  
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;    
import com.gary.test.ws.service.GreetingService;    
public class TestGreetingService {  
    public static void main(String[] args) {  
        //创建WebService客户端代理工厂  
        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();  
        //注册WebService接口  
        factory.setServiceClass(GreetingService.class);  
        //设置WebService地址  
        factory.setAddress("http://localhost:6070/testWebService/GreetingService");  
        GreetingService greetingService = (GreetingService)factory.create();  
        System.out.println("invoke webservice...");  
        System.out.println("message context is:"+greetingService.greeting("gary"));     
    }  
}    

 

applicationContext.xml配置



 
	
	
	

 

 

web.xml配置




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

 

编写完成后,启动tomcat,访问http://localhost:6070/testWebService/GreetingService?wsdl

  • testWebService.zip (25.4 KB)
  • 下载次数: 0
  • lib3.zip (4.2 MB)
  • 下载次数: 0
  • lib4.zip (6.1 MB)
  • 下载次数: 0
  • lib2.zip (9 MB)
  • 下载次数: 0
  • lib1.zip (9.3 MB)
  • 下载次数: 0

你可能感兴趣的:(spring,cfx,接口,webservice,spring+cxf)