Spring与xFire结合开发WebService

?
model对象
属性:id,username,sex,age,address
提供构造函数
每个属性提供getXXX(),setXXX()方法
?
4.编辑applicationContext.xml

?
测试部署是否成功,发布web工程,在IE地址栏中输入: http://127.0.0.1:8080/springxfire/service/,出现链接后: http://127.0.0.1:8080/springxfire/service/HelloService?wsdl
表示部署成功
?
5.测试工程
public static void main(String[] args) { try { Service serviceModel = new ObjectServiceFactory().create(HelloService.class); HelloService service = (HelloService) new XFireProxyFactory().create( serviceModel, "http://127.0.0.1:8080/springxfire/service/HelloService"); //方法一 测试 String str = service.sayHello("世界"); System.out.println(str); //方法二 测试 User user = service.listUserById(1); System.out.println("id:"+user.getId()); System.out.println("username:"+user.getUsername()); System.out.println("sex:"+user.getSex()); System.out.println("age:"+user.getAge()); System.out.println("address:"+user.getAddress()); } catch (MalformedURLException e) { e.printStackTrace(); } catch (RemoteException e) { e.printStackTrace(); } }
发现的问题:在实际项目中,
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>2.0</version>
</dependency>一些jar包与原来项目中的spring jar可能会产生冲突,可以将spring-web jar去掉或覆盖,如下:
(
aopalliance-1.0.jar
avalon-framework-4.1.3.jar
commons-logging-1.1.jar
log4j-1.2.12.jar
logkit-1.0.1.jar
servlet-api-2.3.jar
spring-aop-2.0.jar
spring-beans-2.0.jar
spring-context-2.0.jar
spring-core-2.0.jar
spring-web-2.0.jar
)
其次web.xml中注意加载:xfire,否则测试是否部署成功时,http://.../service/,其实请求的就是在web.xml中配置的servlet