2011年11月8日 星期二

[Java] Deploy Spring Web Service

To run a standalone web service, we may see this post. To create a WAR file, we need extra work. Here is the Project Explorer view of EchoService project:
Step-by-step:
  1. We copy all Spring framework JAR files and commons-logging JAR file to WebContent/WEB-INF/lib/ directory.
  2. We copy applicationContext.xml to WebContent/WEB-INF/directory.
  3. Provide web.xml in WebContent/WEB-INF/directory.
    <?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"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                            http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        version="2.4">
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <servlet>
            <servlet-name>EchoService</servlet-name>
            <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>EchoService</servlet-name>
            <url-pattern>/EchoService</url-pattern>
        </servlet-mapping>
    </web-app>
    
  4. Export a WAR file. (May see this post.)
Enjoy!

沒有留言:

張貼留言