spring+xfire+webservice+helloworld

本文介绍如何使用XFIRE插件与Spring框架整合实现简单的Webservice应用。通过示例代码展示服务端与客户端的搭建过程,包括核心配置文件xfire-servlet.xml的设置及客户端调用方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
spring+xfire+webservice+helloworld
2007年09月07日 星期五 11:24
出处:zhuoda.org 作者:haohao有话说 更新时间:2007-01-27  
由于我们网站的sso系统要实行夸语言,跨服务器的特点,按照领导的指示
要用webService 我就google找了一下关于webService的资料,发现webService还非常复杂,自然我只能最简单的办法来搞了,找了近一个小时,终于在一个老外的网站上看到了关于xfire插件支持java,最重要的是支持spring框架而且非常简单就实现了功能,好在简单提示英语只有初中水平就可以看懂,要不以我这我英语水平是根本看不懂的,我把例子download下来后查看代码,发现老外还是非常友好的代码在ecilpse下打包后直接在tomcat发布就ok了,和想像的结果一样
我就不这webService的例子拿出来和大家分享了。

Echo.java
package org.codehaus.xfire.spring.example;
public interface Echo{
    String echo(String in);
}
EchoImpl.java
package org.codehaus.xfire.spring.example;
public class EchoImpl   implements Echo{
    public String echo(String in){
        return in;
     }
}
applicationContext.xml
<?xml version=1.0 encoding=UTF-8?>
<beans>
     <bean id=echoBean class=org.codehaus.xfire.spring.example.EchoImpl/>
</beans>
这上面的就最简单的spring IoC 下helloworld的例子
这文件xfire-servlet.xml配置是关键:
xfire-servlet.xml
<?xml version=1.0 encoding=UTF-8?>
<beans>
     <bean class=org.springframework.web.servlet.handler.SimpleUrlHandlerMapping>
         <property name=urlMap>
             <map>
                 <entry key=/EchoService>
                     <ref bean=echo>
                 </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=echoBean
         </property>
         <property name=serviceClass>
             <value>org.codehaus.xfire.spring.example.Echo</value>
         </property>
     </bean>
 </beans>
接下来是客户端的test就更简单了
客户端

applicationContext-client.xml
<?xml version=1.0 encoding=UTF-8?>
<beans>
<beanid=testWebService class=org.codehaus.xfire.spring.remoting.XFireClientFactoryBean>
       <property name=serviceClass>
          <value>org.codehaus.xfire.spring.example.Echo</value>
       </property>
       <property name=wsdlDocumentUrl>
         <value>http://127.0.0.1:8080/xfire/EchoService?wsdl</value>
       </property>
      </bean>
<beans>
package test;
import java.util.*;
import junit.framework.TestCase;
import org.codehaus.xfire.spring.example.*;
publicclass WebServiceClientTest extends TestCase {
  Echo echo=
null;
 
static {
 ApplicationContextFactory.init(/test/applicationContext-client.xml);
 }
 
publicstaticvoid main(String[] args) {
 junit.swingui.TestRunner.run(PlayContextDaoTest.
class);
 }
 
protectedvoid setUp() throws Exception {
echo=(Echo)ApplicationContextFactory.getApplicationContext().getBean(testWebService);
 
super.setUp();
 }
protectedvoid tearDown() throws Exception {
 
super.tearDown();
 }
 
public  void testCilient(){
     System.out.print(echo.echo(haoha i haohao));
   }
}
 
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值