在xfire中集成spirng发布webservice

本文讲述了最简单的利用xfire集成spring发布webservice的方法:

1.首先,新建一个Web工程,非WebService工程SprintService,然后加入Spring支持

2.修改web.xml

<? xml version = " 1.0 "  encoding = " UTF-8 " ?>
< web - app version = " 2.4 "  xmlns = " http://java.sun.com/xml/ns/j2ee "  
    xmlns:xsi
= " http://www.w3.org/2001/XMLSchema-instance "  
    xsi:schemaLocation
= " http://java.sun.com/xml/ns/j2ee 
    http: // java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     < context - param >
        
< 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 >

    
< servlet >
        
< servlet - name > xfire </ servlet - name >
        
< servlet - class >
            org.codehaus.xfire.spring.XFireSpringServlet
        
</ servlet - class >
    
</ servlet >

    
< servlet - mapping >
        
< servlet - name > xfire </ servlet - name >
        
< url - pattern >/ services /* </url-pattern>
    </servlet-mapping>    
</web-app>

 


2.新建一个接口:IHelloWorld: (该接口即为WebService的发布接口,我们在下面发布的服务就是该接口)

package  com.prl.webservices;

public   interface  IHelloWorld {
 
int  getSMSCount();
}

3.创建接口实现文件

public   class  HelloWorldImpl  implements  IHelloWorld {

 
public   int  getSMSCount() {
  
return   0 ;
 }

}

 4.修改applicationContext.xml文件:
在最上面加入一行:
 <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />

随后加入:

  < bean  id ="baseWebService"
  class
="org.codehaus.xfire.spring.remoting.XFireExporter"
  lazy-init
="false"  abstract ="true" >
  
< property  name ="serviceFactory"  ref ="xfire.serviceFactory"   />
  
< property  name ="xfire"  ref ="xfire"   />
 
</ bean >

<!--   注意在这里value="com.prl.webservices.IHelloWorld" ,定义了WebService的名称为"IHelloWorld"   -->
 
< bean  id ="helloWorldService"  parent ="baseWebService" >
  
< property  name ="serviceClass"
   value
="com.prl.webservices.IHelloWorld"   />

  
< property  name ="serviceBean"  ref ="HelloWorldImpl"   />
 
</ bean >

 
< bean  id ="HelloWorldImpl"  class ="com.prl.webservices.HelloWorldImpl"   ></ bean >

5.发布后,就可以在地址:http://localhost:8080/SprintWebService/services/IHelloWorld?wsdl 访问该WebService了

 

你可能感兴趣的:(spring,bean,xml,webservice,servlet)