2

我正在使用嵌入式 tomcat(v_ 8.0.33 ) 来运行我的 java 应用程序。它在控制台中引发以下错误:

INFO: Starting Servlet Engine: Apache Tomcat/8.0.33
Jun 11, 2016 2:53:02 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'web-app/servlet/servlet-name'.
Jun 11, 2016 2:53:02 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'web-app/servlet/servlet-class'.
Jun 11, 2016 2:53:02 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'web-app/servlet/init-param/param-name'.
Jun 11, 2016 2:53:02 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'web-app/servlet/init-param/param-value'.
Jun 11, 2016 2:53:02 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'web-app/servlet/init-param'.
Jun 11, 2016 2:53:02 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'web-app/servlet/init-param/param-name'.
Jun 11, 2016 2:53:02 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'web-app/servlet/init-param/param-value'.
Jun 11, 2016 2:53:02 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'web-app/servlet/init-param'.
Jun 11, 2016 2:53:02 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'web-app/servlet/load-on-startup'.
g.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'web-app/servlet-mapping'.
Jun 11, 2016 2:53:02 PM org.apache.tomcat.util.digester.Digester endElement
WARNING:   No rules found matching 'web-app'.
Jun 11, 2016 2:53:02 PM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
INFO: No global web.xml found
Jun 11, 2016 2:53:04 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jun 11, 2016 2:53:06 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]

我认为它映射到正确的 web.xml 文件,但不知何故无法解析它的标签,不知道为什么。是因为这个 tomcat 的版本(某些东西可能已被弃用并且我正在使用)吗?

下面是我的 web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
     see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

  <servlet>
    <servlet-name>REST Servlet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>javax.ws.rs.Application</param-name>
      <param-value>ResourceLoader</param-value>
    </init-param>
    <init-param>
      <param-name>jersey.config.server.provider.packages</param-name>
      <param-value>sran.api.ifscLookup.resources</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>REST Servlet</servlet-name>
    <url-pattern>/Api/*</url-pattern>

  </servlet-mapping>

</web-app>
4

1 回答 1

1

可能在将来的任何时候,如果有人在这一点上也遇到了问题,解决方法是避免使用 web.xml 部署描述符,因为 webapp-runner 中的 XML 解析逻辑存在问题。

而是使用-->在包含 tomcat 实例的Main类中:

Tomcat.addServlet(context, "yourServletName", resourceConfig());
context.addServletMapping("/yourApi/*", "yourServletName");



 private ServletContainer resourceConfig() {
        return new ServletContainer(new ResourceConfig(
                new ResourceLoader().getClasses()));
    }

资源加载器.java

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.core.Application;



public class ResourceLoader extends Application{

    @Override
    public Set<Class<?>> getClasses() {
        final Set<Class<?>> classes = new HashSet<Class<?>>();

        // register root resource
        classes.add(classWhereYouDefinedUrlEndpoint.class);
        return classes;
    }

这可能会节省您的时间:)

于 2016-06-11T20:29:59.467 回答