zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    G-sensor驱动分析
    写i2c_client驱动的两种方式
    TP分析
    JAVA基础知识要点
    springboot-线程池简单使用
    java 实现好看的图形验证码
    正则表达式校验15/18位生份证-JAVA版
    springboot2.X集成HttpClient 发送HTTPS 请求
    linux-修改时区时间
    springboot2.X 在项目启动后执行一段自定义代码
  • 原文地址:https://www.cnblogs.com/hcfan/p/4618902.html
Copyright © 2011-2022 走看看