XFire + Spring 编写webservice
2009-04-20 09:59
190 查看
1、java代码:
IHello.java
package example;
public interface IHello
{
public String hello();
}
package example;
HelloImpl.java
public class HelloImpl implements IHello
{
public String hello()
{
return "hello";
}
}
2、配置文件:
web.xml(注意:classpath:org/codehaus/xfire/spring/xfire.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">
<!-- 配置文件路径 开始 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext*.xml
classpath:org/codehaus/xfire/spring/xfire.xml
</param-value>
</context-param>
<!-- 启动时加载SpringContextServlet -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
</listener>
<!-- 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>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
xfire-servlet.xml (新建这个文件,并且和web.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 class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/testService.ws">
<ref bean="test"/>
</entry>
</map>
</property>
</bean>
<bean id="test" parent="webService" class="org.codehaus.xfire.spring.remoting.XFireExporter">
<property name="serviceBean">
<ref bean="helloBean"/>
</property>
<property name="serviceClass">
<value>example.IHello</value>
</property>
</bean>
<!-- webService base -->
<bean id="webService" class="org.codehaus.xfire.spring.remoting.XFireExporter" abstract="true">
<property name="serviceFactory">
<ref bean="xfire.serviceFactory" />
</property>
<property name="xfire">
<ref bean="xfire" />
</property>
</bean>
</beans>
spring 的配置文件 applicationContext-webService.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="helloBean" class="example.HelloImpl"></bean>
</beans>
IHello.java
package example;
public interface IHello
{
public String hello();
}
package example;
HelloImpl.java
public class HelloImpl implements IHello
{
public String hello()
{
return "hello";
}
}
2、配置文件:
web.xml(注意:classpath:org/codehaus/xfire/spring/xfire.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">
<!-- 配置文件路径 开始 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext*.xml
classpath:org/codehaus/xfire/spring/xfire.xml
</param-value>
</context-param>
<!-- 启动时加载SpringContextServlet -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
</listener>
<!-- 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>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
xfire-servlet.xml (新建这个文件,并且和web.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 class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/testService.ws">
<ref bean="test"/>
</entry>
</map>
</property>
</bean>
<bean id="test" parent="webService" class="org.codehaus.xfire.spring.remoting.XFireExporter">
<property name="serviceBean">
<ref bean="helloBean"/>
</property>
<property name="serviceClass">
<value>example.IHello</value>
</property>
</bean>
<!-- webService base -->
<bean id="webService" class="org.codehaus.xfire.spring.remoting.XFireExporter" abstract="true">
<property name="serviceFactory">
<ref bean="xfire.serviceFactory" />
</property>
<property name="xfire">
<ref bean="xfire" />
</property>
</bean>
</beans>
spring 的配置文件 applicationContext-webService.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="helloBean" class="example.HelloImpl"></bean>
</beans>
相关文章推荐
- 使用xfire+spring编写webservice例子
- 使用xfire+spring编写webservice例子
- 使用xfire+spring编写webservice例子
- XFire+spring 发布webservice 及其客户端调用程序
- 用cxf编写基于spring的webservice之下篇
- Spring集成XFire开发WebService
- 手把手教你spring+xfire配置webservice
- Spring集成XFire开发WebService
- Spring集成XFire开发WebService
- spring中集成xfire开发webservice
- spring配置xfire生成webservice接口 和 调用webservice接口
- Spring集成XFire开发WebService
- xfire发布的Webservice中Spring注入为空的解决方案
- java(xfire)调用java编写的webservice
- WebService学习笔记-使用CXF编写基于Spring的Webservice
- xfire+spring2.5开发webservice接口的两种方式
- 使用xfire编写webservice,并通过C#调用
- Xfire + Spring 远程调用webservice时提示注入的对象是空值,解决办法
- 图文并茂——使用xfire编写webservice,并通过C#调用
- 图文并茂——使用xfire编写webservice,并通过C#调用