CXF简单整合Springmvc

首先配置spring加载配置文件applicationContext.xml




    
    
	

接着配置springmvc配置文件spring-mvc.xml




	
	

	
	

	
	
	

	
	
		
	
	
		
		
		
	

	
	
		
			
				
				
					
						
							text/plain;charset=UTF-8
						
					
				
			
		
	

	
	

下面是写的一个接口和对应的实现类:

接口类

package com.axb.cheney.server;

import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;

@WebService
@SOAPBinding(style = Style.RPC)
public interface AutheCentral {
	
	public String VerifySessionToken(String sessionToken);

}

接口实现类

package com.axb.cheney.serverImpl;

import javax.jws.WebService;

@WebService(endpointInterface="com.axb.cheney.server.AutheCentral") 
public class AutheCentralImpl implements AutheCentral {
    @Override
	public String VerifySessionToken(String sessionToken) {
        return sessionToken;
    }

}

配置cxf-servert.xml:



	
	
	
	
		  
          
    	  
	
	

配置web.xml:



	mybatis
	
	
		contextConfigLocation
		classpath:applicationContext.xml,
        		 classpath:cxf-servlet.xml,
        		 classpath:spring-mvc.xml
    
	

	
	
		字符集过滤器
		encodingFilter
		org.springframework.web.filter.CharacterEncodingFilter
		
			字符集编码
			encoding
			UTF-8
		
	

	
		encodingFilter
		/*
	

	
	
		spring监听器
		org.springframework.web.context.ContextLoaderListener
	

	
		org.springframework.web.util.IntrospectorCleanupListener
	

	
	
		springMvc
		org.springframework.web.servlet.DispatcherServlet
		
			spring mvc 配置文件
			contextConfigLocation
			classpath:spring-mvc.xml
		
		1
	

	
		springMvc
		*.do
	

	
		CXFService
		org.apache.cxf.transport.servlet.CXFServlet
	
	
		CXFService
		/services/*
	

	
		index.jsp
	


启动服务,查看发布接口成功:

CXF简单整合Springmvc_第1张图片

通过浏览器访问发布的接口,输入http://localhost:8090/hyteraWS/services/autheCentral?wsdl

CXF简单整合Springmvc_第2张图片

 

2、编写客户端,测试发布接口,最简单方式就是通过工具自动生成调用代码,以Eclipse为例

CXF简单整合Springmvc_第3张图片

CXF简单整合Springmvc_第4张图片

点击finish,生成工程,如下

CXF简单整合Springmvc_第5张图片

编写简单测试类,并调用接口方法

package com.axb.cheney.test;

import java.rmi.RemoteException;

import com.axb.cheney.server.AutheCentralProxy;

public class Test {

	public static void main(String[] args) throws RemoteException {
		AutheCentralProxy proxy = new AutheCentralProxy();
		String str = proxy.verifySessionToken("hello CXF");
		System.out.println("response:"+str);
	}

}

返回结果:

CXF简单整合Springmvc_第6张图片

嗯嗯,好像很简单的样子,喝喝喝。。。

你可能感兴趣的:(Spring,Spring,MVC)