首页 > 解决方案 > Web.xml 未正确编译

问题描述

我最近尝试从 java7-java8 转换 Eclipse、Google Appengine 项目,因为 GAE 已停止支持 java7(或将在不久的将来支持)。在开始转换之前,该项目运行良好。尝试在本地运行项目时出现此错误:

    java.lang.IllegalStateException: Multiple servlets map to path: /api/add-batch-shelfsurvey: ApiShelfSurveyBatchServlet,com.imobdev.figjam.ApiShelfSurveyBatchServlet

这是该 servlet 在 web.xml 中的条目:

    <servlet>
        <servlet-name>ApiShelfSurveyBatchServlet</servlet-name>
        <servlet-class>com.imobdev.figjam.ApiShelfSurveyBatchServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>ApiShelfSurveyBatchServlet</servlet-name>
        <url-pattern>/api/add-batch-shelfsurvey</url-pattern>
    </servlet-mapping>

这是 web.xml 文件的开头:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" 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">

我已经两次和三次检查 /api/add-batch-shelfsurvey 路径在 web.xml 中是唯一的,但我仍然收到此错误。错误消息中提到的 servlet 发生了变化,但它们都没有到一个路径的多个映射。我发现这些看起来相似但实际上并不相关的线程: https ://github.com/dropwizard/dropwizard/issues/2107 https://bugs.eclipse.org/bugs/show_bug.cgi?id=479865

我不知道它是否相关,但这是我的 appengine-web.xml 文件:

    <appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
        <threadsafe>true</threadsafe>
        <url-stream-handler>urlfetch</url-stream-handler>
        <system-properties>
            <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
            <property name="appengine.file.encoding" value="US-ASCII"/>
        </system-properties>
        <sessions-enabled>true</sessions-enabled>
        <runtime>java8</runtime>
    </appengine-web-app>

标签: javagoogle-app-engineweb.xml

解决方案


我已经设法让项目在 localhost 上运行,并在 Google App Engine 上上传和运行。不幸的是,我不知道到底是什么问题。这些是我采取的步骤: - 从 web.xml 文件中的所有内容中删除 /*。- 在 2.5 xsd 和 3.1 xsd 版本之间多次更改,每次都在 localhost 上运行项目。- 改回 2.5 xsd 并全部改回以 /* 结尾

然后项目在 localhost 和 appengine 上编译并运行良好。如果有人知道更多关于为什么会发生这种情况,请告诉我。


推荐阅读