`

cxf集成spring

 
阅读更多

1、依赖jar包

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-frontend-jaxws</artifactId>
    <version>3.1.8</version>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-transports-http</artifactId>
    <version>3.1.8</version>
</dependency>

 2、web.xml增加配置

	<!-- apache cfx start -->
	<servlet>
		<servlet-name>CXFServlet</servlet-name>
		<servlet-class>
			org.apache.cxf.transport.servlet.CXFServlet
		</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>CXFServlet</servlet-name>
		<url-pattern>/services/*</url-pattern>
	</servlet-mapping>
	<!-- apache cfx end -->

 3、applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Application context definition for PetClinic on JDBC. -->
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
	xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="
			http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
			http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
			http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
			http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
			http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
			http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd
			http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
	
	<!-- apache cxf start -->
	<import resource="classpath*:META-INF/cxf/cxf.xml" />
	<import resource="classpath*:META-INF/cxf/cxf-extension-soap.xml" />
	<import resource="classpath*:META-INF/cxf/cxf-servlet.xml" />
	
	<jaxws:endpoint id="webServiceSample" address="/webServiceSample" implementor="com.zzstxx.webservice.cxf.SchoolWebServiceImpl" />
	<!-- apache cxf end -->
</beans>

 4、接口

package com.zzstxx.webservice.cxf;

import javax.jws.WebService;

@WebService
public interface SchoolWebService {

	// 测试
	public String say(String hello);

	// 获取机构信息
	public String getUnitInfo();

	// 获取用户信息
	public String getUserInfo();

	// 获取年级、班级信息
	public String getGradeClassInfo();

	// 获取学生信息
	public String getStudentInfo();
}

 5、接口实现

package com.zzstxx.webservice.cxf;

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

@WebService(endpointInterface = "com.zzstxx.webservice.cxf.SchoolWebService")
public class SchoolWebServiceImpl implements SchoolWebService {

	public String say(String hello) {
		return hello + "11";
	}

	public String getUnitInfo() {
		
	}

	@Override
	public String getUserInfo() {
		
	}

	@Override
	public String getGradeClassInfo() {
		
	}

	@Override
	public String getStudentInfo() {
		
	}
	

	
}

 测试访问地址:

http://127.0.0.1:8080/services/webServiceSample?wsdl

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics