2

java アプリケーションを実行するために、組み込みの tomcat(v_ 8.0.33 ) を使用しています。コンソールに次のエラーがスローされます。

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

webapp-runner の XML 解析ロジックに問題があるため、回避策は web.xml デプロイメント記述子の使用を避けることです。

代わりに--> tomcat インスタンスを含むMainクラスで使用します。

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



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

ResourceLoader.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 に答える