java - 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>
解决方案
我已经设法让项目在 localhost 上运行,并在 Google App Engine 上上传和运行。不幸的是,我不知道到底是什么问题。这些是我采取的步骤: - 从 web.xml 文件中的所有内容中删除 /*。- 在 2.5 xsd 和 3.1 xsd 版本之间多次更改,每次都在 localhost 上运行项目。- 改回 2.5 xsd 并全部改回以 /* 结尾
然后项目在 localhost 和 appengine 上编译并运行良好。如果有人知道更多关于为什么会发生这种情况,请告诉我。
推荐阅读
- java - 如何编写一个程序来检查字符串中的数字或字母是否遵循给定的模式?
- javascript - 如何在Javascript中循环设置回调函数
- django - @permission_required 装饰器在视图错误中没有返回用户属性
- print-preview - 如何在与 Odoo-14 中的销售模块相同的自定义模块中插入客户预览按钮并编辑 html 报告
- flutter - 如何显式返回`void`?
- android - 从android studio中的视频中提取所有帧的最快方法?
- javascript - 单击以从 React JS 中的字段添加新输入时如何将“添加”按钮固定在顶部
- arrays - 制作一组彩色单元格
- python - 无法通过 Telegram Bot 发送图像
- python - Django - 当前路径,job/all,匹配最后一个。- 但它仍然返回 404