疯狂xml-电子拍卖系统

-----------------Hibernate3、Struts2、Spring2.5、CXF-------------(jar包自行导入)

一、先配置Spring+CXF环境。需要配置web.xml、applicationContext.xml。

配置web.xml

<!-- 指定Spring配置文件的位置 -->
	<context-param>
		<param-name>contextConfigLocation</param-name> 
		<param-value>/WEB-INF/applicationContext.xml</param-value>
	</context-param>

	<!-- 配置Web应用启动时候加载Spring容器 -->
	<listener> 
		<listener-class>org.springframework.web.context.ContextLoaderListener
		</listener-class> 
	</listener>
	
	<!-- 配置CXF的核心Servlet -->
	<servlet>
		<servlet-name>CXFServlet</servlet-name>
		<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<!-- 为CXF的核心Servlet配置URL -->
	<servlet-mapping>
		<servlet-name>CXFServlet</servlet-name>
		<url-pattern>/services/*</url-pattern>
	</servlet-mapping>

 配置applicationContext.xml(注意红字部分)

<?xml version="1.0" encoding="GBK"?>
<!-- 指定Spring配置文件的Schema信息 -->
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
	http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
	http://www.springframework.org/schema/tx 
	http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
	http://www.springframework.org/schema/aop 
	http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
	http://cxf.apache.org/jaxws 
	http://cxf.apache.org/schemas/jaxws.xsd">

	<!-- 导入CXF为扩展Spring提供的几个XML配置文件 -->
	<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" />

	
	<!-- 将容器中指定的Bean暴露成Web Services -->
	<jaxws:endpoint id="auction" 
		implementor="com.xx.auction.ws.impl.AuctionWsImpl" 
		address="/auction" />
</beans>

 发布一个简单service,测试环境搭建成功否。

定义一个接口AuctionWs,如下:

@WebService
public interface AuctionWs {

	String showTime();
}

 定义接口的实现类AuctionWsImpl,代码如下:

@WebService(endpointInterface = "com.xx.auction.ws.AuctionWs",
        serviceName = "auctionWs")
public class AuctionWsImpl implements AuctionWs {

	public String showTime() {
		return ""+new Date();
	}

}

 将项目发布到Tomcat,启动。在浏览器输入:http://localhost:8080/auction/services/auction?wsdl

如果显示如下,说明环境搭建成功!!


疯狂xml-电子拍卖系统_第1张图片
 

(未完)

 

 

 

你可能感兴趣的:(spring,Hibernate,struts2,CXF)