`
javaEE_dev
  • 浏览: 25040 次
  • 性别: Icon_minigender_1
  • 来自: 西安
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

使用XFire+Spring构建Web Service(一)——helloWorld篇

阅读更多
XFire是与Axis 2并列的新一代Web Service框架,通过提供简单的API支持Web Service各项标准协议,帮助你方便快速地开发Web Service应用。

相对于Axis来说,目前XFire相对受欢迎,加上其提供了和Spring集成的支持,在目前的Web Service开源社区拥有众多的追随者。并且因为XFire为Spring提供的支持,使得我们可以很容易在Spring中使用XFire构建Web Service应用。

XFire与Axis2相比具有如下特征:

l         支持一系列Web Service的新标准--JSR181、WSDL2.0 、JAXB2、WS-Security等;

l         使用Stax解释XML,性能有了质的提高。XFire采用Woodstox 作Stax实现;

l         容易上手,可以方便快速地从pojo发布服务;

l         支持Spring、Pico、Plexus、Loom等容器;

l         灵活的Binding机制,包括默认的Aegis,xmlbeans,jaxb2,castor;

l         高性能的SOAP 栈设计;

l         支持Spring、Pico、Plexus、Loom等容器。

XFire与Axis1性能的比较如下:

l         XFire比Axis1.3快2-6倍;

l         XFire的响应时间是Axis1.3的1/2到1/5。

XFire在WebService框架中开始较晚,它从现有的框架中借鉴了许多优秀的理念,力争将Web Service的应用开发难度降到最低。此外,还提供了各种绑定技术、支持多种传输协议,对WebService体系中许多新的规范提供了支持。

下面让我们来看一个XFire于Spring集成的helloWorld的简单例子。

一.实现的功能和特点

    本例具有如下功能和特点:

1) 基于J2EE平台的Web Service服务;

2) 开发方便,配置简单;

3) 与spring无缝集成。

XFire是完全基于流数据处理进行工作的系统,这意味着XFire不是将整个SOAP文档缓存在内存中,而是以管道的方式接收SOAP流数据。这种工作方式的转变带来了可观的性能回报,同时节省了内存的占用。

  XFire从管道中接收一个SOAP请求到返回一个SOAP响应,会经历一系列的阶段。在管道调用的任何一个阶段,XFire都可以添加一些额外的Handler,在对消息进行加工处理后再传入到下一个阶段中。在SOAP请求消息对Web Service发起真正调用之前,分别会经过传输、预转发、转发、策略实施、用户信息处理、预调用、服务调用等阶段。

二.开发环境

    笔者的开发环境描述如下:

1) jdk: 1.5版本;

2) Tomcat:5.5.20;

3) MyEclipse:5.1.1 GA。

三.开发步骤

1. 工程与环境的建立

在MyEclipse中新建Web工程,名为webservice_helloworld。选择该工程后,点击右键选择MyEclipse->Add Web Service Capabilities,弹出Add Web Service Capabilities对话框,点击“Next”,弹出Project Library Configuration对话框,默认选择Core Libraries,点击“Finish”按钮,完成XFire核心包的添加。为了后续的客户端的测试,还需读者加入commons-httpclient.jar包到WEB-INF/lib下。

部署后可看到此时WEB-INF/lib的jar包列表如下:

activation-1.1.jar、commons-beanutils-1.7.0.jar、commons-codec-1.3.jar、commons-httpclient.jar、commons-logging-1.0.4.jar、jaxen-1.1-beta-9.jar、jaxws-api-2.0.jar、jdom-1.0.jar、jsr173_api-1.0.jar、mail-1.4.jar、saaj-api-1.3.jar、saaj-impl-1.3.jar、spring-1.2.6.jar、stax-api-1.0.1.jar、wsdl4j-1.5.2.jar、wstx-asl-3.0.1.jar、xbean-2.1.0.jar、xbean-spring-2.5.jar、xfire-aegis-1.2.2.jar、xfire-annotations-1.2.2.jar、xfire-core-1.2.2.jar、xfire-java5-1.2.2.jar、xfire-jaxws-1.2.2.jar、xfire-jsr181-api-1.0-M1.jar、xfire-spring-1.2.2.jar、XmlSchema-1.1.jar

为了后续的开发和测试,在src目录下分别建立test和webservice目录,分别用于存放测试文件和webservice的相关类。

2.Web Service实现的编写

    在本例中,我们只是做一个helloWorld的简单例子。Web Service服务端提供一个根据输入的名字信息回复相应的helloWorld信息的。例如,当名字为“阿蜜果”时,恢复信息为“hello,阿蜜果”。下面让我们一步一步来开始进行编码。

1)web.xml的配置

一般情况下,我们通过HTTP作为Web Service的传输协议,这样我们只需启动一个Web服务器(如Tomcat,在本例中使用的是Tomcat5.5.20),这样客户端就可以通过HTTP访问到Web Service服务。为了集成Spring容器,XFire专门提供一个XFireSpringServlet,我们可以在web.xml中配置该Servlet,将Spring容器中定义的Web Service在某个URI下发布。

为了能正确使用XFire,需在web.xml中进行相应配置,在该文件中配置XFire的servlet和servlet-mapping。同时因为本实例需要将XFire集成到Spring中,因而需要在web.xml文件中加载Spring的相应配置文件。在本实例中,我们首先在WEB-INF下建立两个配置Spring配置文件,一个为applicationContext.xml,该文件用来定义本工程的bean,一个为xfire-servlet.xml,用来配置XFire的相关bean。修改后的web.xml的内容如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>XFireService</display-name>
    <!-- begin Spring配置 -->
    <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/xfire-servlet.xml</param-value>
    </context-param>
    <listener>
       <listener-class> org.springframework.web.context.ContextLoaderListener
       </listener-class>
    </listener>
     <listener>
       <listener-class>     org.springframework.web.util.IntrospectorCleanupListener
       </listener-class>
    </listener>
    <!-- end Spring配置 -->

    <!-- begin XFire 配置 -->
    <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>*.ws</url-pattern>
    </servlet-mapping>
    <servlet>
       <!-- 配合Spring容器中XFire一起工作的Servlet-->
       <servlet-name>xfireServlet</servlet-name>
       <servlet-class>org.codehaus.xfire.spring.XFireSpringServlet</servlet-class>
    </servlet>
    <servlet-mapping>
       <servlet-name>xfireServlet</servlet-name>
       <!-- 在这个URI下开放Web Service服务 -->
       <url-pattern>/service/*</url-pattern>
    </servlet-mapping>
    <!-- end XFire 配置 -->
</web-app>

    2)Web Service的接口类HelloWorld.java和对应实现类HelloWorldImpl.java

为了用Web Service完成HelloWorld功能,我们首先在src/webservice目录下建立接口类HelloWold.java。它仅包含一个sayHelloWorld(String name)的方法,其详细内容如下:


package webservice;

/** *//**
*HelloWorld的接口类.
*/
publicinterface HelloWorld {
    /** *//**
     *对名字为name的人打招呼.
     *@paramname名字
     *@return返回打招呼的字符串
     */
    String sayHelloWorld(String name);
}
我们还需要建立一个对应的实现类,来实现sayHelloWorld的功能,该实现类即为HelloWorldImpl.java。该类的详细内容如下:
package webservice;
/** *//**
*HelloWorld的实现类.
*/
publicclass HelloWorldImpl implements HelloWorld {
    public String sayHelloWorld(String name) {
       String helloWorld = "hello," + name;
       return helloWorld;
    }
}

3)Spring配置文件applicationContext.xml和xfire-servlet.xml的配置

首先我们在applicationContext.xml文件中配置对应的bean——HelloWorldBean,该xml文件的内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="HelloWorldBean" class="webservice.HelloWorldImpl"/>
</beans>
     这个配置文件很简单,在此不详述。

XFire为Spring提供了方便易用的导出器XFireExporter,借助该导出器的支持,我们可以在Spring容器中将一个POJO导出为Web Service。HelloWorld是业务服务类,在此拥有一个sayHelloWorld的方法,我们希望将此方法开放为Web Service。在实际应用中,如果某个类具有众多的方法,而其中的某些方法不需要开放为Web Service的情况下,我们可以定义一个窄接口,该接口中只需定义那些开放为Web Service的业务方法。

将一个业务类所有需要开放为Web Service的方法通过一个窄接口来描述是值得推荐的作法,这让Web Service的接口显得很“干净”。其次,XFire的导出器也需要服务接口的支持,因为它采用基于接口的动态代理技术。

窄接口中的方法在真实的系统中可能需要引用其它的业务类或DAO获取数据库中的真实数据,为了简化实例,我们在此简化了实例。

下面让我们看看在xfire-servlet.xml文件中导出器的设置,该文件内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <!-- 引入XFire预配置信息 -->
    <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
    <!—定义访问的url-->
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
       <property name="urlMap">            
           <map>                
              <entry key="/HelloWorldService.ws">                 
                  <ref bean="HelloWorldService" />                
              </entry>            
           </map>        
       </property>    
    </bean>    

    <!-- 使用XFire导出器 -->
    <bean id="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter" lazy-init="false" abstract="true">
       <!-- 引用xfire.xml中定义的工厂 -->
       <property name="serviceFactory" ref="xfire.serviceFactory" />
       <!-- 引用xfire.xml中的xfire实例 -->
       <property name="xfire" ref="xfire" />
    </bean>
    <bean id="HelloWorldService" parent="baseWebService">
       <!-- 业务服务bean -->
       <property name="serviceBean" ref="HelloWorldBean" />
       <!-- 业务服务bean的窄接口类 -->
       <property name="serviceClass" value="webservice.HelloWorld" />
    </bean>
</beans>

在上面的配置中,我们可以看到,在该配置文件中引入了xfire.xml这个Spring配置文件。它是在XFire核心JAR包中拥有一个预定义的Spring配置文件,它定义了XFire在Spring中必须用到的一些Bean和资源,需要引入这个预定义的配置文件。从该配置文件中可以看出,我们通过XFireExporter将业务类导出为Web Service,对于任何导出器,我们都需要引入XFire环境,即serviceFactory和xfire,这是标准的配置。ServiceFactory是XFire的核心类,它可以将一个POJO生成为一个Web Service。

在本实例中,我们通过定义一个baseWebService,其余的webService配置都将该bean作为父bean,这样可以简化Spring的配置,不需要多次引入serviceFactory和xfire。

3. Web Service的测试

    在上一步操作完成之后,我们的这个简单的Web Service已经编写完毕,下面让我们来看看自己的劳动成果吧。

    在浏览器中输入地址:http://localhost:8080/webservice_helloworld/HelloWorldService.ws?wsdl,我们可以看到HelloWorldService对应的WSDL信息,阅读这个WSDL文档,我们可以知道HelloWorld的sayHelloWorld方法已经被成功地发布为Web Service了。只要拿到这个WSDL就可以开发相应的客户端调用程序了。

XFire为访问服务端Web Service提供了各种方便的方式:我们一般根据服务地址和窄接口类创建客户调用程序。

  在不能获得服务窄接口类的情况下,XFire允许我们通过WSDL文件生成客户端调用程序,通过指定服务接口的方式调用服务。

1)通过WSDL文件生成客户端调用程序

首先我们通过http://localhost:8080/webservice_helloworld/HelloWorldService.ws?wsdl我们可以获得WSDL文件HelloWorldService.wsdl,并将其放在src目录下面,接着我们通过程序访问该WSDL文件,并调用需测试的方法。此时测试类WebServiceClientTest.java的内容如下所示:


package test;

import org.codehaus.xfire.client.Client;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import webservice.HelloWorld;

/** *//**
*Copyright2007GuangZhouAmigo.
*Allrightreserved.  
*HelloWorld的webservice的测试类.
*@author<a href="mailto:xiexingxing1121@126.com">AmigoXie</a>
*@version1.0
*Creationdate:2007-9-16-下午05:36:05
*/
publicclass WebServiceClientTest {
    HelloWorld helloWorld = null;

    publicstaticvoid main(String[] args) throws Exception {
       WebServiceClientTest test = new WebServiceClientTest();
       test.testClient();
    }
   
    publicvoid testClient() throws Exception {
       String wsdl = "HelloWorldService.wsdl"; //对应的WSDL文件
       Resource resource = new ClassPathResource(wsdl);
       Client client = new Client(resource.getInputStream(), null); //根据WSDL创建客户实例
      
       Object[] objArray = new Object[1];
       objArray[0] = "阿蜜果";
       //调用特定的Web Service方法
       Object[] results = client.invoke("sayHelloWorld", objArray);
       System.out.println("result: " + results[0]);
    }
}
运行该类,可得到如下输出结果:

result: hello,阿蜜果

可看出运行结果正确。

2)根据服务地址创建客户端调用程序

    接着让我们来看一个根据服务地址创建客户端调用程序的例子。我们可以通过测试类来测试Web Service的正确性,下面让我们来看一个简单的测试类,首先我们在src/test目录建立WebServiceClientTest.java文件,并在src目录下建立客户端调用的Spring配置文件client.xml。在client.xml配置文件中我们定义了一个testWebService的bean,该bean访问wsdlDocumentUrl为http://localhost:8080/webservice_helloworld/HelloWorldService.ws?wsdl的WSDL。该xml文件的详细内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="testWebService" class="org.codehaus.xfire.spring.remoting.XFireClientFactoryBean">
       <property name="serviceClass">         
   <value>webservice.HelloWorld</value>      
       </property>     
        <property name="wsdlDocumentUrl">        
<value>http://localhost:8080/webservice_helloworld/HelloWorldService.ws?wsdl</value>      
        </property>     
     </bean>
</beans>

     在WebServiceClientTest.java文件中获得HelloWorld,并调用它的sayHelloWorld方法来完成测试,该类的详细内容如下所示:

package test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import webservice.HelloWorld;

/** *//**
*HelloWorld的webservice的测试类.
*/
publicclass WebServiceClientTest {
    HelloWorld helloWorld = null;

    publicstaticvoid main(String[] args) {
       WebServiceClientTest test = new WebServiceClientTest();
       test.testClient();
    }

    publicvoid testClient() {
       ApplicationContext ctx = new ClassPathXmlApplicationContext(
              "client.xml");
       helloWorld = (HelloWorld) ctx.getBean("testWebService");
       System.out.println(helloWorld.sayHelloWorld("阿蜜果"));
    }
}

    在启动webservice_helloworld工程的情况下,运行WebServiceClientTest类,可看到控制台包含如下信息:

    hello,阿蜜果

    由此可看出调用Web Service成功。

四.总结

    与Axis相比,在实施Web Service时XFire更加简洁高效,并且XFire对Spring提供了强大的支持,可以非常方便地在Spring中使用XFire实施Web Service,因此XFire在短短的时间里成为了受Web Service开发者喜爱的框架。

  XFire为客户端提供了多种访问Web Service的方式,如果可以获取客户端的窄接口类,则可以采用窄接口类调用Web Service。如果仅能获取WSDL,XFire也可以采用动态反射的机制调用Web Service。XFire为Eclipse提供了一个可以根据WSDL生成客户端存根代码的插件,相信XFire也将为其它非Java语言提供类似的插件。

技术可用性的一个很大的标准是它是否方便测试,XFire提供多种方式进行Web Service的测试,简单方便,给Web Service开发人员的测试工作带来了福音。

在本文中,笔者通过一个简单的helloWorld的Web Service例子,详细地说明了用XFire+Spring构建Web Service时配置文件的相关配置,以及测试的各种方法,也让读者见识了XFire与Spring的无缝集成,希望对读者学习XFire有点帮助。

posted on 2007-09-26 09:39 阿蜜果 阅读(12400) 评论(49)  编辑  收藏 所属分类: Web Service




FeedBack:
# re: 使用XFire+Spring构建Web Service
2007-09-27 10:49 | 千里冰封

用EJB的方式也可以构建webservice
不过, spring听说是很牛的  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service
2007-09-27 11:23 | 易初风云

可以,请问一下java远程调用方法共有多少种方式呢?那种比较好呢?  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service
2007-09-27 12:53 | 千里冰封

多少种方式?不太清楚,找到自己适用的就可以了  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service
2007-09-27 17:37 | cnjar

1)通过WSDL文件生成客户端调用程序

不如直接这样:
Client client = new Client(new URL("http://localhost:8080/webservice_helloworld/HelloWorldService.ws?wsdl"));  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2007-09-28 17:56 | bigheadbird

我按照你 的例子写的,却完全没有反应,提示找不到资源,想问一下,可需要
add spring capabilities?我这种情况可能是什么原因?  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2007-09-28 17:59 | bigheadbird

我是在Web Service的测试这里就没有反应。
  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2007-09-29 09:43 | bigheadbird

我找到原因了,applicationContext.xm 文件名我少写了个p,晕死,我知道了 ,不用add spring capabilities。  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇[未登录]
2007-09-29 11:24 | Bruce

能不能把目录结构列出来。。。俺是初学者  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2007-09-29 11:35 | 阿蜜果

@Bruce
本篇与下篇的例子的目录结构请参见:
http://www.blogjava.net/amigoxie/gallery/image/9492.html  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇[未登录]
2007-09-29 11:39 | Bruce

谢谢!谢谢!偶现在就去看!  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇[未登录]
2007-09-29 11:43 | Bruce

好用了,谢谢阿蜜果:)
  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2007-11-05 10:31 | dong2590

java.lang.NoSuchMethodError: javax.xml.namespace.QName.<init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V

我按照你的写了..可是在Tomcat启动时就报这种错误..网上有说这种错误.不过很模糊..希望能指导一下.谢谢.
我用的是JDK1.4.MyEclipse5.0,Tomcat5.0的.  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇[未登录]
2007-11-05 13:00 | 阿蜜果

用Tomcat5.5才行,貌似5.0不行  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2007-11-05 15:00 | dong2590

@阿蜜果
我到原因了~是JAR包冲突的问题~Javax.xml.namespace.QName的方法定义太旧,用xfile的lib里面的stax-api-1.0.1.jar和stax-utils-20040917.jar
并删除旧的javax.xml.namespace.QName如jaxrpc.jar问题就好了..但是现在又出来个新的问题~
我在web.xml作了如下配置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml,/WEB-INF/classes/xfire-servlet.xml</param-value>
</context-param>
但是在Tomcat启动时.却报错.
ERROR DispatcherServlet:227 - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/XFire-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/XFire-servlet.xml]
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/XFire-servlet.xml]

我这就搞不懂了~为什么会去到WEB-INF下面去找?  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-03-17 09:42 | zqj


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.handler.SimpleUrlHandlerMapping' defined in ServletContext resource [/WEB-INF/xfire-servlet.xml]: Can't resolve reference to bean 'HelloWorldService' while setting property 'urlMap[/HelloWorldService.ws]'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'HelloWorldService' defined in ServletContext resource [/WEB-INF/xfire-servlet.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'HelloWorldService' defined in ServletContext resource [/WEB-INF/xfire-servlet.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.<init>(Z)V


启动和一直报以上ERROR  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇[未登录]
2008-03-24 17:28 | 阿飞

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/ws/commons/schema/resolver/URIResolver

at org.codehaus.xfire.client.Client.initFromDefinition(Client.java:262)
at org.codehaus.xfire.client.Client.<init>(Client.java:236)
at org.codehaus.xfire.client.Client.<init>(Client.java:246)
at com.info.gh.webservice.example1.WebServiceClientTest.testClient(WebServiceClientTest.java:56)
at com.info.gh.webservice.example1.WebServiceClientTest.main(WebServiceClientTest.java:45)

请问老报上面的错误,是什么原因呀  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-03-24 17:28 | jackie

你好姐姐,我也向你要一份工程 关于webservice的工程,关于webservice的工程我都想要,还有能给我一起传基本关于webservice的书吗?


我的邮箱: jackie-zheng@163.com

现在这里谢谢了  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-03-24 17:33 | jackie

为什么我按照你的步骤建工程的时候怎么就没有xfire-servlet。xml这个文件呢?  回复  更多评论
 
# Class not found: webservice.HelloWorld[未登录]
2008-03-28 10:09 | lixin

能不能给您的工程了,我做的发布不起来!谢谢  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-04-16 16:59 | yangpan

log4j:WARN Please initialize the log4j system properly.
2008-4-16 16:56:36 org.apache.catalina.core.StandardContext start
严重: Error listenerStart
2008-4-16 16:56:36 org.apache.catalina.core.StandardContext start
严重: Context [/webservice] startup failed due to previous errors  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-04-16 17:02 | yangpan

@yangpan
我是按照 你 的方法做的.可是编译的时候就报了上面的错误...
我找了很久没有找到...你帮我看看...  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇[未登录]
2008-04-16 20:40 | 阿蜜果

@阿飞
错误很清楚呢,有jar包没有包括进去。
@jackie
我待会给你发一份
@yangpan
留个邮箱吧!也发一份给你  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-04-17 10:13 | yangpan

,,谢谢...
yangpanwww@126.com

阿密果,你真的是太好了,,,,愿意交我这个朋友不...
我的QQ:609865047

  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-04-17 15:01 | yangpan

还有.....我对比了我们 lib\下的所有 的.jar 包 发现xfire-spring-1.2.2.jar jsr173_api-1.0.jar 这两个我lib里没有 (可能就是这个原因)

还有,你上面说" 点击右键选择MyEclipse->Add Web Service Capabilities,弹出Add Web Service Capabilities对话框,点击“Next”,弹出Project Library Configuration对话框,默认选择Core Libraries,点击“Finish”按钮,完成XFire核心包的添加。" 我按照做了,,,lib下没有一个包, lib里的包是我在网上下的xfire-1.1.1,我全拷贝进lib里了,但 里面有没有上面的.jar包.

我用的是MyEclipse6.0,Tomcat5.5.
呵呵..你耐耐心,,帮我看看.....谢谢咯......  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-04-17 17:43 | yangpan

喔,,...上面的问题我知道可,,
我加了log4j.properties 后...
出现 Document root element "beans", must match DOCTYPE root "null" 错误..我的是spring2.0
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"" target="_new" rel="nofollow">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-2.0.xsd">

而且我也把 XFire Core lib 中有Spring1.2.6 也删除了
网上都被我找遍了,,还是没有发现....
大姐,帮帮我.....
  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-04-17 18:05 | yangpan

亲爱的阿蜜果
上面的Spring配置文件applicationContext.xml和xfire-servlet.xml

是怎么结合在一起的......

上面的错误我解决了,,但又有一个错误:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'webservice.example2.UserServiceImpl' is defined



呜~~~~~~~我都搞了三天了,,,,你就帮帮我了,,,

快帮你的 项目 给我....我

  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-04-18 11:22 | yangpan


呜~~~~~~~~~~~~~

错误找到咯,,,,,,,三天啊. 呜~~~~~~~~~

是我的.xml 写错了文件

我该骂..你们骂我吧  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-05-22 15:31 | Nic

我的ContextLoaderListener 这个监听器加载的时候有问题 是不是缺少某个JAR包啊?。能给我发一份吗?我的邮箱是:morosefingerling@gmail.com 不胜感激  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-05-22 17:56 | Nic

我的问题解决了。。不知道大家是不是和我遇到的问题一样,简单说一下:
我用的是MyEclipse6.0
一、用Eclipse Add Web Service Capabilities 这样使用的是Spring1.2的包,而我使用的是Spring2.0 这样产生了冲突。删除1.2的就OK了
二、web.xml中 <param-value>/WEB-INF/classes/applicationContext.xml,/WEB-INF/classes/xfire-servlet.xml</param-value>才能找到对应的文件,xfire-servlet.xml文件放在工程的/WEB-INF/xfire-servlet.xml和,/WEB-INF/classes/xfire-servlet.xml 下。
希望对大家有帮助,还是要多谢阿蜜果。有空可以聊聊天啊 16640813 :)  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-06-04 18:29 | 小猫

继续研究种  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-06-20 10:27 | lhy

能不能发份代码我看看,我按照你写的还是没配出来,搞了好几天了,郁闷啊
邮箱:li_hy2004@163.com
谢谢了  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-06-23 10:15 | lhy

我的问题解决了,和nic一样是spring包的问题,没想到xfire的包里已经有spring的包了,我又加了spring2.0的包-_-!
多谢阿蜜瓜^^  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-07-20 09:53 | lifeng

为什么我删了那个spring1.x的包就不行呢,说org/codehaus/xfire/spring/xfire.xml不存在。。。还要做什么改动吗?  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇[未登录]
2008-09-08 16:30 | jane

文章简介实用.一试成功.真是舒服的体验过程.  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-09-19 14:22 | 杨培海

阿米果老师,Xfire怎么传递数组啊?  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-11-18 16:53 | 汤帅

请问在创建客户端的时候必须要有一个HelloWorld这个类吗?  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-12-09 21:53 | dmx

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/Credentials
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:108)
at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
at org.codehaus.xfire.client.Client.invoke(Client.java:336)
at org.codehaus.xfire.client.Client.invoke(Client.java:368)
at test.WebServiceClientTest.testClient(WebServiceClientTest.java:25)
at test.WebServiceClientTest.main(WebServiceClientTest.java:14)


帮我看看怎么回事好么?谢谢!  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2008-12-10 20:20 | dmx

@dmx
版主 救助啊  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2009-04-15 19:05 | fire1

这个问题 是由于application.xml文件的头部信息不兼容  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2009-05-13 16:56 | A.biao

Retrieving document at 'null'.
log4j:WARN No appenders could be found for logger (org.springframework.beans.factory.xml.XmlBeanDefinitionReader).
log4j:WARN Please initialize the log4j system properly.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/methods/RequestEntity
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2328)
at java.lang.Class.getConstructor0(Class.java:2640)
at java.lang.Class.getConstructor(Class.java:1629)
at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:108)
at org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
at org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
at org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:79)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:114)
at org.codehaus.xfire.client.Client.invoke(Client.java:336)
at org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)
at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)
at $Proxy0.sayHelloWorld(Unknown Source)
at test.WebServiceClientTest.testClient(WebServiceClientTest.java:27)
at test.WebServiceClientTest.main(WebServiceClientTest.java:18)

按啊蜜果老师的教程做到测试时就报这个错误了!能帮帮我找出什么原因吗?
还有那个 Retrieving document at 'null'.
  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2009-05-15 16:47 | nihao

2009-5-15 8:46:04 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [client.xml]
2009-5-15 8:46:04 org.springframework.context.support.AbstractRefreshableApplicationContext refreshBeanFactory
信息: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=3043939]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [testWebService]; root of BeanFactory hierarchy
2009-5-15 8:46:04 org.springframework.context.support.AbstractApplicationContext refresh
信息: 1 beans defined in application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=3043939]
2009-5-15 8:46:04 org.springframework.core.CollectionFactory <clinit>
信息: JDK 1.4+ collections available
2009-5-15 8:46:04 org.springframework.context.support.AbstractApplicationContext initMessageSource
信息: Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@f62373]
2009-5-15 8:46:04 org.springframework.context.support.AbstractApplicationContext initApplicationEventMulticaster
信息: Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@7c6768]
2009-5-15 8:46:04 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [testWebService]; root of BeanFactory hierarchy]
Retrieving document at 'null'.  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2009-07-14 16:49 | birbe

Could not open ServletContext resource [/WEB-INF/xfire-servlet.xml] 是怎么回事,另外 为什么访问地址是http://localhost:8080/webservice_helloworld/HelloWorldService.ws?wsdl 其中 webservice_helloworld不知道是怎么回事  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2009-07-14 17:01 | tanglong

阿米果姐姐,小弟我是初学着,能不能也给我发一份啊 我的邮箱是
tanglongjava@163.com  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇[未登录]
2009-07-22 17:11 | tang

出现如下同样问题:

2007-11-05 15:00 | dong2590

@阿蜜果
我到原因了~是JAR包冲突的问题~Javax.xml.namespace.QName的方法定义太旧,用xfile的lib里面的stax-api-1.0.1.jar和stax-utils-20040917.jar
并删除旧的javax.xml.namespace.QName如jaxrpc.jar问题就好了..但是现在又出来个新的问题~
我在web.xml作了如下配置:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml,/WEB-INF/classes/xfire-servlet.xml</param-value>
</context-param>
但是在Tomcat启动时.却报错.
ERROR DispatcherServlet:227 - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/XFire-servlet.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/XFire-servlet.xml]
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/XFire-servlet.xml]

我这就搞不懂了~为什么会去到WEB-INF下面去找??
为什么呢?
能加我QQ吗?QQ:52016639==>验证提示:唐  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2009-12-16 19:00 | Will云

按照你的教程还是比较容易的,只是我想问下,xfire-servlet.xml这个文件是不是只能放在webinf下?因为我一改位置,就会报错,而applicationcontext.xml换了位置就没问题的  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2010-01-14 14:10 | changchang9977

你把工程发给我一份吧!邮箱:changchang9977@sina.com  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2010-03-16 16:30 | 云运

我最后需要把wsdl文件发给别人的,我怎么才能找到或得到这个wsdl文件呀?  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2010-03-16 16:31 | 云运

很急的,我的QQ:929304944,能给我发到我的Q邮箱吗?或加我的Q。  回复  更多评论
 
# re: 使用XFire+Spring构建Web Service(一)——helloWorld篇
2010-06-22 18:41 | greenfish

我把第一个例子自己练习了下,有这个错误。。
Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not find operation with name sayHelloWorld
at org.codehaus.xfire.client.Client.invoke(Client.java:366)
at test.WebServiceClientTest.testClient(WebServiceClientTest.java:31)
at test.WebServiceClientTest.main(WebServiceClientTest.java:20)

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics