zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    zookeeper配置
    redis前端启动和后台启动的区别
    SpringMVC接受JSON参数详解及常见错误总结我改
    SpringMVC @RequestBody接收Json对象字符串
    spring MVC 如何接收前台传入的JSON对象数组
    springMVC 接收json字符串参数
    mysql数据库user表host字段的%问题
    mysql.user表中Host为%的含义
    开店攻略: 零售店铺经营的三大原则
    开店攻略: 如何巧妙接近顾客
  • 原文地址:https://www.cnblogs.com/duyunchao-2261/p/7454045.html
Copyright © 2011-2022 走看看