`
java虫
  • 浏览: 532286 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

XFire学习

阅读更多
看了下XFire,记录相关资料。

一.概述
    官网http://xfire.codehaus.org/

    XFire 是 codeHaus 组织提供的一个开源框架,它构建了 POJO 和 SOA 之间的桥梁,主要特性就是支持将 POJO 通过非常简单的方式发布成 Web 服务,这种处理方式不仅充分发挥了 POJO 的作用,简化了 Java 应用转化为 Web 服务的步骤和过程,也直接降低了 SOA 的实现难度,为企业转向 SOA 架构提供了一种简单可行的方式。


二.技术架构

   XFire框架是一种基于Servlet技术的SOA应用开发框架,要正常运行基于XFire应用框架开发的企业应用,除了XFire框架本身之外,还需要JDK和Servlet容器的支持(XFire 支持在多种 Servlet 容器中运行,包括 Websphere、Weblogic、TOMCAT 等)

三.XFire的使用
详细讲解http://www.ibm.com/developerworks/cn/java/j-lo-xfire/#h1

四.Spring集成XFire
XFire可以很好的集成到Spring中,Spring的代码已经做了这方面的集成。
将 POJO 发布成 Web 服务的基本步骤如下
1.创建 Web 服务接口
声明和实现该 Web 服务对外暴露的接口;
接口Echo.java:
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;
     }
}

META-INF/xfire/service.xml文件可以省略了,因为web服务的定义在xfire-servlet.xml中可以找到。

2.配置普通bean
   下面要做的工作就是配置了,在WEB-INF文件夹下创建applicationContext.xml文件,这是Spring的配置文件,如果你使用其他的Spring配置文件,可以将下面的bean添加到那个配置文件中:
<?xml version=1.0 encoding=UTF-8?>
<beans>
     <bean id=echoBean class=org.codehaus.xfire.spring.example.EchoImpl/>
</beans>

定义了echoBean,这个Bean就是我们的实现类,当然你也可以在这个文件中定义其他的需要Spring管理的bean。

3.创建xfire-servlet.xml文件
     在WEB-INF文件夹下创建xfire-servlet.xml文件,根据Spring规范,这个文件名起做xfire-servlet.xml,其中xfire是web.xml配置的DispatcherServlet的名称,这个文件的配置是关键:
xfire-servlet.xml
<?xml version=1.0 encoding=UTF-8?>
<beans>
<bean class=org.springframework.web.servlet.handler.SimpleUrlHandlerMapping>
<property name=urlMap>
<map>
<!--这个文件的上半部分将EchoService这个URL和echo这个bean联系在一起-->
<entry key=/EchoService><ref bean=echo></entry>
</map>
</property>
</bean>
<!--echo定义了Web服务的bean和服务接口,其中echoBean是我们在applicationContext.xml中配置的那个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>
<!--serviceBean是实现的类-->
<property name=serviceBean><ref bean=echoBean</property>
<!--serviceClass是接口-->
<property name=serviceClass>
<value>org.codehaus.xfire.spring.example.Echo</value>
</property>
</bean>
</beans>


4.修改web.xml
<?xml version="1.0" encoding="ISO-8859-1"?> 
<!DOCTYPE web-app 
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
"http://java.sun.com/dtd/web-app_2_3.dtd"> 
<web-app> 
<context-param> 
<param-name>contextConfigLocation</param-name> 
<param-value>/WEB-INF/applicationContext.xml 
classpath:org/codehaus/xfire/spring/xfire.xml</param-value> 
</context-param> 
<listener> 
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 
<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>/*</url-pattern> 
</servlet-mapping> 
………
</web-app> 


需要注意这个文件的三个部分:
1.在定义contextConfigLocation参数时一定要加上
classpath:org/codehaus/xfire/spring/xfire.xml[/url]

[color=red]2[/color].定义listener:org.springframework.web.context.ContextLoaderListener

[color=red]3[/color].定义DispatcherServlet:xfire 
  
调用这个Web服务 [url]http://localhost:8080/xfire/EchoService[/url]
查看wsdl文档 [url]http://localhost:8080/xfire/EchoService?wsdl[/url]

以上即为一个在spring中集成XFire的例子。


  


  
分享到:
评论
2 楼 641216927 2009-08-20  
学习XFire.请问一下,如果不整合spring的话,配置文件怎么写?xfire-servlet.xml , web.xml
1 楼 figeonline 2007-11-27  
值得參考。

相关推荐

Global site tag (gtag.js) - Google Analytics