zoukankan      html  css  js  c++  java
  • Spring发布WebService

    Maven:

    <!-- WebService -->
    		<dependency>
    			<groupId>org.apache.cxf</groupId>
    			<artifactId>cxf-rt-frontend-jaxws</artifactId>
    			<version>3.0.4</version>
    		</dependency>
    		<dependency>
    			<groupId>org.apache.cxf</groupId>
    			<artifactId>cxf-rt-transports-http</artifactId>
    			<version>3.0.4</version>
    		</dependency>
    		<dependency>
    			<groupId>org.apache.neethi</groupId>
    			<artifactId>neethi</artifactId>
    			<version>3.0.3</version>
    		</dependency>


    这里的org.apache.neethi的版本最好是3.0.3   不然你使用了别人的webservice可能会报错   我试过用3.0.2报错
    : javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: java.lang.RuntimeException: Cannot create a secure XMLInputFactory

    具体原因不清楚

    还有记得别加这个

    不然还是报错 

    Caused by: org.apache.cxf.BusException: No DestinationFactory was found for the namespace http://schemas.xmlsoap.org/soap/http.


    webxml:

    <servlet>
    		<servlet-name>CXFService</servlet-name>
    		<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>CXFService</servlet-name>
    		<url-pattern>/ws/*</url-pattern>
    	</servlet-mapping>
    url-pattern自定义,就是你访问webservice的地址

    Springxml:

    <!-- 接口的实现类声明 -->
    	<bean id="自定义" class="写你webservice接口的实现类" />
    
    	<!-- 默认自带日志输出 -->
    	<bean id="inMessageInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor" />
    	<bean id="outLoggingInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
    
    	<!-- 发布WebService -->
    	<jaxws:server id="自定义" serviceClass="这里写你接口不是实现类"
    		address="/自定义访问webservice的地址">
    		<jaxws:serviceBean>
    			<ref bean="自定义接口的实现类" />
    		</jaxws:serviceBean>
    		<jaxws:inInterceptors>
    			<ref bean="inMessageInterceptor" />
    		</jaxws:inInterceptors>
    		<jaxws:outInterceptors>
    			<ref bean="outLoggingInterceptor" />
    		</jaxws:outInterceptors>
    	</jaxws:server>

    webservice接口:

    package ws.spring.server;  
      
    import javax.jws.WebMethod;  
    import javax.jws.WebService;  
      
    @WebService  
    public interface UserWS {  
        @WebMethod  
        public UserBean getUserById(int id);  
    }  


    webservice实现类 :

    package ws.spring.server;  
      
    import javax.jws.WebService;  
      
    @WebService  
    public class UserWSImpl implements UserWS {  
        public UserWSImpl(){  
            System.out.println("初始化 UserWSImpl");  
        }  
        @Override  
        public UserBean getUserById(int id) {  
            System.out.println("server getUserById:"+id);  
            return new UserBean(1, "张三");  
          
        }  
      
    }  
    运行输入地址: /ws/自定义的webservice 地址

  • 相关阅读:
    WPF操作ini 文件的读写示例
    WPF调用图片路径,或资源图片
    WPF笔记一
    WPF 获取程序路径的一些方法,根据程序路径获取程序集信息
    10进制转62进制,实现穷举指定位数的所有密码组合(暴力破解)
    匿名对象和object的转换
    构造函数和:this()的应用
    WPF TextBox自动滚动到最户一行
    C#接口的使用场合,接口应用
    读匿名object对象的属性值
  • 原文地址:https://www.cnblogs.com/zhousiwei/p/10625781.html
Copyright © 2011-2022 走看看