4-15 3,339 views
Resin是一款非常流行的Web Application服务器,可以部署servlet和JSP,同时,Resin也可以作为Web Service服务器。使用Resin部署Web Service的步骤如下。
配置Resin
在Resin配置文件中添加以下语句使其支持Web Service:
1 |
<system-property javax.xml.stream.XMLInputFactory="com.sun.xml.internal.stream.XMLInputFactoryImpl" /> |
配置web.xml
配置servlet,对Http请求使用WSSpringServlet实例进行处理:
1 2 3 4 5 6 7 8 9 |
<servlet> <servlet-name>JAXWSServlet</servlet-name> <servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>JAXWSServlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> |
配置Spring上下文
绑定URL和Web Service:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:ws="http://jax-ws.dev.java.net/spring/core" xmlns:wss="http://jax-ws.dev.java.net/spring/servlet" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd"> <context:component-scan base-package="com.vshangping.server.webservice" /> <wss:binding url="/testWebService"> <wss:service> <ws:service bean="#testWebService" /> </wss:service> </wss:binding> </beans> |
实现Web Service
1 2 3 4 5 6 7 8 9 10 11 12 |
@Service("testWebService") @WebService(targetNamespace = "com.vshangping.server.webservice", serviceName = "TestWebService") public class TestWebService { @Resource private MachineService machineService; public Machine getMachine(Integer id) { return machineService.get(id); } } |
编译打包后部署到Resin中,访问/webservice/testWebService,如下所示:
版权属于: 我爱我家
原文地址: http://magicwt.com/2015/04/15/%e4%bd%bf%e7%94%a8resin%e9%83%a8%e7%bd%b2web-service/
转载时必须以链接形式注明原始出处及本声明。