Java after the encoding completes the WebService server, you can run a Main method to publish the WebService service, but after the actual deployment of the service to the servers, must not also run the main method, so we need to launch the server when the service is published. and runs throughout the lifecycle of the server.
Main Method Publishing Service (available for test classes)
public static void Main (string[] args) {endpoint.publish ("http://172.18.100.52:9090/medical", new Medicalservicecontroller ()); System.out.println ("****[Server ready ... WebService released successfully. ]");}
Deploying to a server we typically publish a service when initialized in a servlet:
Package cn.sccl.mms.web;import java.io.ioexception;import javax.servlet.genericservlet;import javax.servlet.servlet;import javax.servlet.servletconfig;import javax.servlet.servletexception ;import javax.servlet.servletrequest;import javax.servlet.servletresponse;import javax.xml.ws.endpoint;/** * is only used to publish the WebService interface service that is provided to 114 when the spring container is initialized, the service is started * * @author lijianbo * */public class MedicalServlet implements servlet {@Overridepublic void destroy () {// TODO Auto-generated Method stub} @Overridepublic servletconfig getservletconfig () {// TODO Auto-generated method stubreturn null;} @Overridepublic string getservletinfo () {// TODO Auto-generated method Stubreturn null;} /** * Release 114webService service * ("This servlet does not process any business logic, just to publish a Web service"); */@Overridepublic void init (servletconfig arg0) throws servletexception { Endpoint.publish ("Http://172.18.100.52:9090/medical", new medicalservicecontroller ()); System.out.println ("****[ server ready ... WebService released successfully. ]");} @Overridepublic void service (SERVLETREQUEST ARG0, SERVLETRESPONSE ARG1) throws servletexception, ioexception {system.out.println ("This servlet does not process any business logic, just to publish a Web service");}}
The configuration is also required in Web. XML:
<!--endpoint.publish 114webService--><servlet><servlet-name>medicalservlet</servlet-name ><servlet-class>cn.sccl.mms.web.medicalservlet</servlet-class><load-on-startup>1</ Load-on-startup></servlet><servlet-mapping><servlet-name>medicalservlet</servlet-name ><url-pattern>/servlet/medicalServlet</url-pattern></servlet-mapping>
Note: ① to set the load level to 1, which guarantees that the servlet will be initialized when the service is started.
<load-on-startup>1</load-on-startup>
This gives us the opportunity to launch the WebService service when we start the server.
This article from "Jianbo" blog, reproduced please contact the author!
Publish a WebService service to the server in Java