• CXF+Spring 搭建的WebService


    1.创建类

    2.接口编写

    1 package com.fan;
    2 
    3 import javax.jws.WebService;
    4 
    5 @WebService
    6 public interface IHelloWorld {
    7     void SayHi(String str);
    8 }// end

    3.实现类编写

     1 package com.fan;
     2 
     3 import javax.jws.WebService;
     4 
     5 import org.springframework.stereotype.Service;
     6 
     7 @Service("RHelloWorld")
     8 @WebService(endpointInterface = "com.fan.IHelloWorld")
     9 public class RHelloWorld implements IHelloWorld {
    10 
    11     public void SayHi(String str) {
    12         // TODO Auto-generated method stub
    13         System.out.println("SayHi:" + str);
    14     }
    15 
    16 }// end

    4.web配置文件编写

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
     3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     4     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
     5     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
     6     <display-name>Fan</display-name>
     7     <filter>
     8         <filter-name>characterEncodingFilter</filter-name>
     9         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    10         <init-param>
    11             <param-name>encoding</param-name>
    12             <param-value>UTF-8</param-value>
    13         </init-param>
    14     </filter>
    15     <filter-mapping>
    16         <filter-name>characterEncodingFilter</filter-name>
    17         <url-pattern>/*</url-pattern>
    18     </filter-mapping>
    19     <servlet>
    20         <display-name>CXFServlet</display-name>
    21         <servlet-name>CXFServlet</servlet-name>
    22         <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    23         <load-on-startup>1</load-on-startup>
    24     </servlet>
    25     <servlet-mapping>
    26         <servlet-name>CXFServlet</servlet-name>
    27         <url-pattern>/*</url-pattern>(ps:编写路径)
    28     </servlet-mapping>
    29 
    30 
    31     <listener>
    32         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    33     </listener>
    34 
    35     <context-param>
    36         <param-name>contextConfigLocation</param-name>
    37         <param-value>
    38         classpath:beans.xml(ps:beans配置文件)
    39       </param-value>
    40     </context-param>
    41 </web-app>

    5.编写beans.xml

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <beans xmlns="http://www.springframework.org/schema/beans"
     3 xmlns:context="http://www.springframework.org/schema/context"
     4     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
     5     xsi:schemaLocation="   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
     6      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     7     http://cxf.apache.org/jaxws 
     8     http://cxf.apache.org/schemas/jaxws.xsd">
     9     
    10     <import resource="classpath:META-INF/cxf/cxf.xml"/>
    11     <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
    12     <context:component-scan base-package="com.fan" />    
    13     <jaxws:endpoint id="appWsServer" implementor="#RHelloWorld"  address="/appWsServer"/>(ps:实现类)
    14     
    15 </beans>

    6.关键步骤,导入所需要的包

    暂时没有精选最少导入哪些包,这里是我导入的包。

     7.验证路径

    http://localhost:8888/MyWebService/appWsServer?wsdl

    请大神将需要的包给我精简一下。

    欢迎指正:haizi2014@qq.com
  • 相关阅读:
    现在的技术QQ群为什么都变成了这样?效率高也是有弊端的?
    【php】php中mail()不可用,php中sendmail不能用的解决方法
    Cannot validate since no PHP executable is set. Use the setting 'php.validate.executablePath' to configure the PHP executable.无法使用PHP可执行的设置。设置php.validate。executablePath配置PHP可执行文件。
    20150907自动化测试之Appinum For Android(前篇)
    [摘]关于目标管理
    婚恋网站应该有视频功能
    GIS的双屏显示模式是一个实用的创新
    移动产品将越分越细
    基于开源GIS软件的电子政务地理信息应用解决方案
    手机长途话费应再降!
  • 原文地址:https://www.cnblogs.com/hcfan/p/4618902.html
Copyright © 2020-2023  润新知