webService简单的整合Spring+CXF(六)

一。创建web项目,引入jar包

二。创建SEI接口

三。创建实现类。

四。配置Spring的配置文件

创建 applicationContext.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:jaxws="http://cxf.apache.org/jaxws"
    xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
                            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
                            http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
    <!-- jaxWs:endPoint发布soap服务的协议,对Endpotin类封装 -->
    <jaxws:endpoint address="/hello" implementor="ws.cxf.service.HelloName"></jaxws:endpoint>
    
    <!-- jaxWs:server 发布soap服务的协议,对JaxWsServerFactoryBean类封装 -->
    <jaxws:server address="/weather" serviceClass="ws.cxf.service.WeatherInterface" >
        <jaxws:serviceBean>
         <ref bean="WeatherInterface" />
        </jaxws:serviceBean>
    </jaxws:server>
    <bean name="WeatherInterface" class="ws.cxf.service.WeatherInterfaceImpl">
    </bean>                            
</beans>

 

五。配置xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <!-- 设置Spring配置环境 -->
  <display-name>ws_2_cxf_spring_server</display-name>    
  <context-param>
  <!-- contextConfigLocation不能修改 -->
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  
  <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
  <!-- 配置CXF的Servlet -->
  <servlet>
  <servlet-name>CXF</servlet-name>
  <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
  </servlet>
  <servlet-mapping>
  <servlet-name>CXF</servlet-name>
  <url-pattern>/ws/*</url-pattern>
  </servlet-mapping>
  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

六。启动tomcat,输入项目路径

http://localhost:8080/项目名/ws/weather?wsdl

 

posted @ 2017-08-30 17:04  duyunchao  阅读(275)  评论(0编辑  收藏  举报