MAVEN项目基于SSM框架配置CXF实现

maven项目自动支持jar包的添加,因此,我们配置正确的情况下,不需要我们引入任何jar包。

首先。配置pom.xml文件

在<dependencies></dependencies>中间加入CXF的jar包依赖
<dependencies>
<!-- webservice  cxf配置 -->
		<dependency>
		  <groupId>org.apache.cxf</groupId>
		  <artifactId>cxf-core</artifactId>
		  <version>3.0.11</version>
		</dependency>
		<dependency>
		<groupId>org.apache.cxf</groupId>
		  <artifactId>cxf-rt-bindings-soap</artifactId>
		  <version>3.0.11</version>
		</dependency>
		<dependency>
		  <groupId>org.apache.cxf</groupId>
		  <artifactId>cxf-rt-databinding-jaxb</artifactId>
		  <version>3.0.11</version>
		</dependency>
		<dependency>
		  <groupId>org.apache.cxf</groupId>
		  <artifactId>cxf-rt-frontend-jaxrs</artifactId>
		  <version>3.0.11</version>
		</dependency>
		<dependency>
		  <groupId>org.apache.cxf</groupId>
		  <artifactId>cxf-rt-frontend-simple</artifactId>
		  <version>3.0.11</version>
		</dependency>
		<dependency>
	  <groupId>org.apache.cxf</groupId>
	  <artifactId>cxf-rt-frontend-jaxws</artifactId>
	  <version>3.0.11</version>
	   </dependency>
		<dependency>
		  <groupId>org.apache.cxf</groupId>
		  <artifactId>cxf-rt-transports-http</artifactId>
		  <version>3.0.11</version>
		</dependency>
		<dependency>
		  <groupId>org.apache.cxf</groupId>
		  <artifactId>cxf-rt-transports-udp</artifactId>
		  <version>3.0.11</version>
		</dependency>
		<dependency>
		  <groupId>org.apache.cxf</groupId>
		  <artifactId>cxf-rt-wsdl</artifactId>
		  <version>3.0.11</version>
		</dependency>

	</dependencies>

其次配置。添加ApplicationContext-webservice.xml文件。

文件配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:oxm="http://www.springframework.org/schema/oxm"
	xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
                 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
                 http://www.springframework.org/schema/oxm 
                 http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd 
                 http://cxf.apache.org/jaxws 
                 http://cxf.apache.org/schemas/jaxws.xsd">


	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />


	
	<bean id="MobileAppWebService" class="com.msunsoft.webService.impl.AppEnvironmentalHygieneHtml">
		</bean>
        <jaxws:endpoint implementor="#MobileAppWebService" address="/MobileAppWebService"/>


	
	
</beans>

红色代码是你将暴露的接口

最容易忽略的一点是

将配置的ApplicationContext-webservice.xml加入Spring框架的扫描范围里面

在ApplicationContext.xml文件中加入

<import resource="classpath:spring/ApplicationContext-webservice.xml"/>

文明名称可能不同,配置到你们的扫描文件中即可

添加WEB.XML文件配置:

 <!-- 接口的实现 -->
	<servlet>
		<servlet-name>CXF</servlet-name>
		<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
	</servlet>

	<!-- 所有来自/ws/*的请求交给cxf处理 -->
	<servlet-mapping>
		<servlet-name>CXF</servlet-name>
		<url-pattern>/webService/*</url-pattern>
	</servlet-mapping>

下面是接口的编写,代码如下:

@WebService
public interface MobileAppWebService {
	@WebMethod
	public String  SavaEnvironmentalHygieneHtml(@WebParam(name="text")String re);
}

实现类代码如下所示:

@WebService(endpointInterface="com.msunsoft.webService.MobileAppWebService",serviceName="MobileAppWebService")
public class AppEnvironmentalHygieneHtml implements MobileAppWebService{

	@Override
	public String SavaEnvironmentalHygieneHtml(String re) {
		// TODO Auto-generated method stub
		return "SUCCESS";
	}

最后启动项目,测试是否发布成功

http://服务器ip地址:端口号/项目名称/Service包名称/接口名称?wsdl


现在就可以把地址发给别人测试了。客户端怎么写,自己百度吧


阅读更多 登录后自动展开
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页