This article describes the simplest way to use xfire to integrate spring to publish webservice:
1. First, create a Web project, non-WebService project SprintService, and then add Spring support
2. modify 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. Create an interface: ihelloworld: (this interface is the publishing interface of WebService. The service we publish below is this interface)
Package com. prolactin. WebServices;
Public interface ihelloworld {
Int getsmscount ();
}
3. Create an interface implementation file
Public class helloworldimpl implements ihelloworld {
Public int getsmscount (){
Return 0;
}
}
4. Modify the applicationcontext. xml file:
Add a line at the top:
<Import resource = "classpath: ORG/codehaus/xfire/spring/xfire. xml"/>
Then join:
<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>
<! -- Note: Here value = "com. prolactin. WebServices. ihelloworld" defines the WebService name as "ihelloworld" -->
<Bean id = "helloworldservice" parent = "basewebservice">
<Property name = "serviceclass"
Value = "com. prolactin. WebServices. ihelloworld"/>
<Property name = "serviceBean" ref = "HelloWorldImpl"/>
</Bean>
<Bean id = "HelloWorldImpl" class = "com. prolactin. webservices. HelloWorldImpl"> </bean>
5. After the release, you can go to the address http: // localhost: 8080/SprintWebService/services/IHelloWorld? The wsdl has accessed the WebService.