maven+springMVC+xfire 喜欢ヅ旅行 2022-08-06 01:22 103阅读 0赞 转载自:http://blog.csdn.net/moliqin/article/details/6897581 1. pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>xfireWebservice</groupId> <artifactId>xfireWebservice</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>3.0.6.RELEASE</version> <exclusions> <exclusion> <artifactId>spring-beans</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-context</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-core</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>3.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <version>3.0.6.RELEASE</version> </dependency> <dependency> <groupId>org.codehaus.xfire</groupId> <artifactId>xfire-all</artifactId> <version>1.2.6</version> <exclusions> <exclusion> <artifactId>junit</artifactId> <groupId>junit</groupId> </exclusion> <exclusion> <artifactId>spring</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> </dependencies> </project> 2 WEB-INF/xfire-servlet.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" /> <bean id="hello" class="com.service.HelloImpl"></bean> <!-- <bean id="world" class="com.service.WorldImpl"></bean> \--> <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="urlMap"> <map> <entry key="/hello"> <ref bean="echo" /> </entry> <!-- <entry key="/world"> <ref bean="world" /> </entry> \--> </map> </property> </bean> <bean id="echo" class="org.codehaus.xfire.spring.remoting.XFireExporter"> <property name="serviceFactory"> <ref bean="xfire.serviceFactory" /> </property> <property name="xfire"> <ref bean="xfire" /> </property> <property name="serviceBean"> <ref bean="hello" /> </property> <property name="serviceClass"> <value>com.service.Hello</value> </property> </bean> <!-- <bean id="world" class="org.codehaus.xfire.spring.remoting.XFireExporter"> <property name="serviceFactory"> <ref bean="xfire.serviceFactory" /> </property> <property name="xfire"> <ref bean="xfire" /> </property> <property name="serviceBean"> <ref bean="world" /> </property> <property name="serviceClass"> <value>com.service.World</value> </property> </bean> \--> </beans> 3 WEB-INF/web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app\_2\_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app\_2\_5.xsd" id="WebApp\_ID" version="2.5"> <display-name>xfireWebservice</display-name> <context-param> <param-name>contextConfigLocation</param-name> <!-- <param-value>classpath:org/codehaus/xfire/spring/xfire.xml</param-value> --> <param-value>classpath:xfire-servlet.xml</param-value> </context-param> <servlet> <servlet-name>xfire</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>xfire</servlet-name> <url-pattern>/services/\*</url-pattern> </servlet-mapping> </web-app> 4 source package com.service; public interface Hello \{ public String say(String name); \} ============================= package com.service; public class HelloImpl implements Hello \{ public String say(String name) \{ return name + " : 欢迎学习WebService!!"; \} \} ======================================================= Client test code import org.springframework.context.support.FileSystemXmlApplicationContext; import com.service.Hello; public class Main \{ /\*\* \* @param args \*/ public static void main(String\[\] args) \{ FileSystemXmlApplicationContext xmlContext =new FileSystemXmlApplicationContext("G://workspace/xfireWebservice/src/main/resources/application.xml"); Hello h = (Hello) xmlContext.getBean("testWebService"); System.out.println(h.say("crazy jack")); \} \} application.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="testWebService" class="org.codehaus.xfire.spring.remoting.XFireClientFactoryBean"> <property name="serviceClass"> <value>com.service.Hello</value> </property> <property name="wsdlDocumentUrl"> <value>http://127.0.0.1:8080/xfireWebservice/services/hello?wsdl</value> </property> </bean> </beans>
还没有评论,来说两句吧...