JAX-WS Web service on Tomcat without sun-jaxws.xml

前端 未结 4 2099
礼貌的吻别
礼貌的吻别 2021-02-13 12:02

I am trying to minimize required configuration while deploying JAX-WS-based Web service on Tomcat. With the introduction of Servlet 3.0 (supported by Tomcat 7+), web.xml

4条回答
  •  不知归路
    2021-02-13 13:01

    To have JAX-WS support in Tomcat you must configure:

    • WEB-INF/sun-jaxws.xml
    • WSServletContextListener
    • WSServlet

    Unfortunately it is hard to omit the WEB-INF/sun-jaxws.xml file but there is easier way to omit web.xml configuration because of Servlet 3.0 API.

    You can do something like this:

    @WebServlet(name = "ServiceServlet" , urlPatterns = "/service", loadOnStartup = 1)
    public class Servlet extends WSServlet {
    
    }
    

    and

    @WebListener
    public class Listener implements ServletContextAttributeListener, ServletContextListener {
    
        private final WSServletContextListener listener;
    
        public Listener() {
            this.listener = new WSServletContextListener();
        }
    
        @Override
        public void attributeAdded(ServletContextAttributeEvent event) {
            listener.attributeAdded(event);
        }
    
        @Override
        public void attributeRemoved(ServletContextAttributeEvent event) {
            listener.attributeRemoved(event);
        }
    
        @Override
        public void attributeReplaced(ServletContextAttributeEvent event) {
            listener.attributeReplaced(event);
        }
    
        @Override
        public void contextInitialized(ServletContextEvent sce) {
            listener.contextInitialized(sce);
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent sce) {
            listener.contextDestroyed(sce);
        }
    }
    

    I have tested it on Tomcat-8.5.23 version and it works. But remember that you still must have WEB-INF/sun-jaxws.xml file.

    
        
    
    

提交回复
热议问题