Spring是目前最流行的JavaEE Framework
Spring和XFire可以通過多種方式結合
在web
<servlet>
<servletname>XFireServlet</servlet name>
<servletclass>
orgcodehaus xfire spring XFireSpringServlet
</servletclass>
</servlet>
<servletmapping>
<servletname>XFireServlet</servlet name>
<urlpattern>/servlet/XFireServlet/*</url pattern>
</servletmapping>
<servletmapping>
<servletname>XFireServlet</servlet name>
<urlpattern>/services/*</url pattern>
</servletmapping>
<contextparam>
<paramname>contextConfigLocation</param name>
<paramvalue>
classpath:org/codehaus/xfire/spring/xfirexml
/WEBINF/applicationContext xml
</paramvalue>
</contextparam>
<listener>
<listenerclass>
orgspringframework web context ContextLoaderListener
</listenerclass>
</listener>
以下是完整的web
<?xml version=encoding= UTF ?>
<webapp version=
xmlns=http://java sun com/xml/ns/j ee
xmlns:xsi=http://www w org/ /XMLSchema instance
xsi:schemaLocation=http://java sun com/xml/ns/j ee
http://javasun com/xml/ns/j ee/web app_ _ xsd >
<contextparam>
<paramname>contextConfigLocation</param name>
<paramvalue>
classpath:org/codehaus/xfire/spring/xfirexml
/WEBINF/applicationContext xml
</paramvalue>
</contextparam>
<listener>
<listenerclass>
orgspringframework web context ContextLoaderListener
</listenerclass>
</listener>
<servlet>
<servletname>XFireServlet</servlet name>
<servletclass>
orgcodehaus xfire spring XFireSpringServlet
</servletclass>
</servlet>
<servletmapping>
<servletname>XFireServlet</servlet name>
<urlpattern>/servlet/XFireServlet/*</url pattern>
</servletmapping>
<servletmapping>
<servletname>XFireServlet</servlet name>
<urlpattern>/services/*</url pattern>
</servletmapping>
</webapp>
定義接口
package org
ccsoft; publicinterface HelloWS {
public String sayHello(String sb);
}
實現服務
package org
ccsoft; publicclass HelloWSImp implements HelloWS {
public String sayHello(String sb) {
// TODO Autogenerated method stub
returnHello +sb;
}
}
將上文中實現的服務
<?xml version=
encoding= UTF ?>
<beans xmlns=http://www springframework org/schema/beans
xmlns:xsi=http://www w org/ /XMLSchema instance
xsi:schemaLocation=
http://wwwspringframework org/schema/beans http://www
springframework org/schema/beans/spring beans xsd > <bean id=
helloWS class= org ccsoft HelloWSImp />
<bean name=helloService class= org codehaus xfire spring ServiceBean >
<property name=serviceBean ref= helloWS />
<property name=serviceClass value= org ccsoft HelloWS />
<property name=inHandlers >
<list>
<ref bean=addressingHandler />
</list>
</property>
</bean><bean id=
addressingHandler class=
org codehaus xfire addressing AddressingInHandler />
</beans>
From:http://tw.wingwit.com/Article/program/Java/ky/201311/29182.html