xfire 集成spring的webservices
1. xfire + spring 发布webservice 使用xfire+spring发布webservice其实很简单,遵循一下几个步骤即可 1. 想要发布成文webservice的类,必须实现接口 2. 3个配置文件(后面详细说) 下面针对以上步骤详细说明 关于1中的要求,给个例子就明白了 User.java 代码 package com.zjh.xfire; public class User { private String name; private int age; private Set SGroupUsers = new HashSet(0); private Set SUserDepts = new HashSet(0); public void setName(String name) { this.name=name; } public void setAge(int age) { this.age=age; } public String getName() { return name; } public int getAge() { return age; } public Set getSGroupUsers() { return this.SGroupUsers; } public void setSGroupUsers(Set SGroupUsers) { this.SGroupUsers= SGroupUsers; } public Set getSUserDepts() { return this.SUserDepts; } public void setSUserDepts(Set SUserDepts) { this.SUserDepts= SUserDepts; } } Itest.java 代码 package com.zjh.xfire; public interface IHello { public String hello(); public String helloTo(String name); public void getUserData(User user); } HelloImpl.java 代码 package com.zjh.xfire; public class HelloImpl implements IHello { public String hello() { return "hello"; } public String helloTo(String name) { return " hello " + name + "!"; } public void getUserData(User user) { System.out.println("hello"+name); System.out.println("age"+age); } } 就这样写就可以了 关于三个配置文件 web.xml修改如下 xml 代码 log4jConfigLocation /WEB-INF/classes/log4j.properties contextConfigLocation /WEB-INF/classes/applicationContext*.xml classpath:org/codehaus/xfire/spring/xfire.xml org.springframework.web.context.ContextLoaderListener org.springframework.web.util.Log4jConfigListener org.springframework.web.util.IntrospectorCleanupListener xfire org.springframework.web.servlet.DispatcherServlet xfire *.ws index.jsp 这里注意 classpath:org/codehaus/xfire/spring/xfire.xml 必须要写进去 xfire-servlet.xml 新建这个文件,并且和web.xml放在同一个文件夹 注意: 名称和位置都不能变(也许可以改,我不知道) xml 代码 com.zjh.xfire.IHello spring 的配置文件 applicationContext-webService.xml xml 代码 查看wsdl http://localhost:8080/xfiretest/testService.ws?wsdl 报错相关文章: [XFire]如何根据WSDL生成Server Side的代码吖? Ant脚本发布XFire WebService 客户端 xfire客户端问题 xfire插件自动生成客户端代码后,调用时报错(已解决) 推荐圈子: Tapestry 更多相关推荐 org.codehaus.xfire.fault.XFireFault: Unable to write 'com.zjh.xfire.User@1ee4648' ['com.zjh.xfire.User]. Type is unknown. at org.codehaus.xfire.aegis.type.basic.ObjectType.handleNullType(ObjectType.java:234) at org.codehaus.xfire.aegis.type.basic.ObjectType.writeObject(ObjectType.java:169) at org.codehaus.xfire.aegis.AegisBindingProvider.writeParameter(AegisBindingProvider.java:200) at org.codehaus.xfire.service.binding.AbstractBinding.writeParameter(AbstractBinding.java:273) at org.codehaus.xfire.service.binding.WrappedBinding.writeMessage(WrappedBinding.java:90) at org.codehaus.xfire.soap.SoapSerializer.writeMessage(SoapSerializer.java:80) at org.codehaus.xfire.transport.http.HttpChannel.writeWithoutAttachments(HttpChannel.java:56) at org.codehaus.xfire.transport.http.CommonsHttpMessageSender.getByteArrayRequestEntity(CommonsHttpMessageSender.java:422) at org.codehaus.xfire.transport.http.CommonsHttpMessageSender.send(CommonsHttpMessageSender.java:360) at org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:123) 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) 郁闷了半天,google了一下,是xfire传递数据时绑定的问题 当遇到需要映射POJO或配置WebService接口方法返回类型(如集合类型)时,需要进行绑定,此时aegis的绑定为建立.aegis.xml的文件。 解决方法在User.java文件下加User.aegis.xml 再在tomcat重新发布一下工程,运行http://localhost:8080/xfiretest/testService.ws?wsdl 成功!!!