maven+springMVC+xfire

转载自: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>
package com.xfire.core.client; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.codehaus.xfire.client.XFireProxyFactory; import org.codehaus.xfire.service.Service; import org.codehaus.xfire.service.binding.ObjectServiceFactory; import com.xfire.core.entity.UserInfo; import com.xfire.core.service.IUserInfoService; /** *@author jilongliang *@Date 2012-3-5 * */ public class UserInfoClient { public static void main(String[] args) { getServiceList(); setServiceList(); } static String url = "http://localhost:8081/xfire/services/UserInfo"; /** * */ public static void getServiceList() { Service service = new ObjectServiceFactory() .create(IUserInfoService.class); try { IUserInfoService iAddressService = (IUserInfoService) new XFireProxyFactory() .create(service, url); List list = (ArrayList) iAddressService .getAddressList(); System.out.println("一共多少条数据:" + list.size()); for (Iterator iter = list.iterator(); iter.hasNext();) { UserInfo a = iter.next(); System.out.println(a); } } catch (MalformedURLException e) { e.printStackTrace(); } } public static void setServiceList() { Service service = new ObjectServiceFactory() .create(IUserInfoService.class); try { IUserInfoService iAddressService = (IUserInfoService) new XFireProxyFactory() .create(service, url); List listAdd = new ArrayList(); UserInfo address = new UserInfo(); address.setIdentifier(1); address.setCountry("中國"); address.setProivice("廣東省"); address.setCity("陽江"); address.setAddress("廣東陽春"); address.setPostCode("1111111"); address.setExist(false); address.setArrary(new String[] { "22", "23", "24" }); listAdd.add(address); address.setIdentifier(2); address.setCountry("中國"); address.setProivice("廣東省"); address.setCity("陽江"); address.setAddress(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值