JSPCN主页
|
JSP空间
|
网站制作
|
JSP下载
|
JSP论坛
|
JSP教程
|
关于JSPCN
|
联系我们
做最专业的JSP中文网站
当前位置
:
首页
--
JAVA技术
--
Spring
文章搜索:
关键字
标题
JSP中文网内容管理系统(JCMS)
JSP虚拟主机
网络笔记本
网摘,图片,笔记收藏
虚拟服务器
JSPCN文章目录分类
JSP配置
[
219
]
JSP基础
[
136
]
中文问题
[
69
]
上传问题
[
27
]
JAVABEAN
[
46
]
数据库
[
212
]
文件操作
[
126
]
图片声音
[
17
]
JSP其他
[
57
]
时间相关
[
16
]
JAVAMAIL
[
72
]
STRUTS
[
144
]
开发工具
[
28
]
教程系列
[
157
]
JSP实例
[
89
]
JAVA基础
[
421
]
APPLET
[
78
]
JAVA网络
[
179
]
Applica
[
115
]
Servlet
[
98
]
XML
[
163
]
J2ME
[
257
]
J2EE
[
374
]
考试相关
[
63
]
JAVA线程
[
90
]
EJB
[
261
]
Swing
[
26
]
Java API
[
141
]
声音图片
[
28
]
异常处理
[
33
]
JAVA实例
[
290
]
JAVA类
[
139
]
SUN
[
89
]
Hibernate
[
6
]
JMX
[
8
]
Spring
[
34
]
本版推荐文章
快速上手Spring--4.安装和使用IDE
Spring中IOC的实现
品味Spring 的魅力
Spring开发指南0.8版(By夏昕)
Spring简介
spring持久化
spring提供的事务管理
使用分布式缓存来群集Spring远程服务
Spring对log4j的增强
Spring与iBATIS的集成
Learn Spring in spring(三)
在SPRING中实现事务暂停
Spring MultiAction的简单示例
Spring: A Developer's Notebook...
Spring: A Developer's Notebook...
POJO应用框架:Spring与EJB3.0的比较
学习如何在EJB应用程序中使用Spring
[评论]从Spring VS. EJB3.0想到的男女问题
在Spring中使用JDO
Spring 框架简介
本版热点文章
快速上手Spring--4.安装和使用IDE
spring持久化
POJO应用框架:Spring与EJB3.0的比较
根据petclinic项目手把手教你剖析SpringFram...
Spring与iBATIS的集成
Spring简介
使用Spring的JdbcTemplate实现分页功能
使用分布式缓存来群集Spring远程服务
在SPRING中实现事务暂停
spring提供的事务管理
Spring: A Developer's Notebook...
Spring对log4j的增强
Learn Spring in spring(三)
Spring MultiAction的简单示例
Spring中IOC的实现
Spring: A Developer's Notebook...
Spring 入门(一个简单的例子)
Spring开发指南0.8版(By夏昕)
[评论]从Spring VS. EJB3.0想到的男女问题
Spring--内容与形式并重[2005.5]
相关文章链接
在Spring集成XFire
作者: 文章来源:
访问次数:6次 加入时间:2007年04月09日
XFire可以很好的集成到Spring中,Spring的代码已经做了这方面的集成。
首先,我们先创建我们的Web服务,采用接口和实现类的方式:
接口MathService.java:
package com.kuaff.xfire.samples;
public interface MathService
{
public long add(int p1, int p2);
}
实现类:
package com.kuaff.xfire.samples;
public class MathServiceImpl implements MathService
{
public long add(int p1, int p2)
{
return p1 + p2;
}
}
META-INF/xfire/service.xml文件可以省略了,因为web服务的定义在xfire-servlet.xml中可以找到。
下面要做的工具就是配置了。
在WEB-INF文件夹下创建applicationContext.xml文件,这是Spring的配置文件,如果你使用其他的Spring配置文件,可以将下面的bean添加到那个配置文件中:
<?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="mathBean" class="com.kuaff.xfire.samples.MathServiceImpl"/>
</beans>
定义了mathBean,这个Bean就是我们的实现类,当然你也可以在这个文件中定义其他的需要Spring管理的bean。
在WEB-INF文件夹下创建xfire-servlet.xml文件,根据Spring规范,这个文件名起做xfire-servlet.xml,其中xfire是web.xml配置的DispatcherServlet的名称:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/MathService">
<ref bean="math"/>
</entry>
</map>
</property>
</bean>
<bean id="math" 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="mathBean"/>
</property>
<property name="serviceClass">
<value>com.kuaff.xfire.samples.MathService</value>
</property>
</bean>
</beans>
这个文件的上半部分将MathService这个URL和math这个bean联系在一起。下半部分定义了Web服务的bean和服务接口。其中mathBean是我们在applicationContext.xml中配置的那个Bean。
最后一步就是修改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>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<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。
2. 定义listener: org.springframework.web.context.ContextLoaderListener
3. 定义DispatcherServlet: xfire
这样,你就可以访问http://localhost:8080/xfire/MathService来调用这个Web服务,也可以通过网址http://localhost:8080/xfire/MathService?wsdl来查看wsdl文档。
Copyright © 2002-2005
JSP
CN.net. All rights reserved.
JSP中文网 备案序号:蜀ICP备05001583号
成都恒海科技发展有限公司 成都市一环路南二段6号新瑞楼三楼8号