我最近尝试从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>
这是因为路径/api/add-batch-shelfsurvey
可能已经注册,然后尝试检查web.xml中的所有<servlet-mapping>
部分,如果你有任何@WebServlet
注释,那么检查urlPatterns={"..."}
如果你有两个定义同时app服务器将不知道哪个是正确的。
我设法让项目在localhost上运行,然后在Google App Engine上运行。不幸的是,我不知道究竟是什么问题。这些是我采取的步骤: - 从web.xml文件中删除所有/ *。 - 在版本2.5 xsd和3.1 xsd之间多次更改,每次在localhost上运行项目。 - 更改回2.5 xsd并将所有内容更改为以/ *结尾
Project然后在localhost和appengine上编译并运行良好。如果有人知道为什么会发生这种情况,请告诉我。