我发现了一些类似的问题,但我无法解决我的错误。我构建了一场战争并使用 tomcat7 maven 插件对其进行了测试,它与 Jetty maven 插件配合得很好。因为我必须在 tomcat 上部署它,所以我想使用 tomcat7 maven 插件。
所以我的 web.wml 文件是:
<!-- environment variable for path of database -->
<env-entry>
<env-entry-name>paramName</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>FilePath</env-entry-value>
</env-entry>
<!-- Auto scan REST service -->
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<!-- this need same with resteasy servlet url-pattern -->
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/mypath</param-value>
</context-param>
<context-param>
<param-name>resteasy.wider.request.matching</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>ResteasyServlet</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ResteasyServlet</servlet-name>
<url-pattern>/mypath/*</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
我的java文件是:
@Path("/mypath")
公共类我的服务{
@Context
private HttpServletRequest request;
@GET
@Path("allData")
@Produces(MediaType.APPLICATION_JSON)
public Response readAllData() {
...
}
我的 pom.xml 配置如下:
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/${project.build.finalName}</path>
</configuration>
</plugin>
</plugins>
<finalName>mypath</finalName>
</build>
因此,当我启动 mvn tomcat7:run ok 时,我可以通过 URL http://localhost:8080/mypath 访问我的站点,但我得到了一些调用 http://localhost:8080/mypath/mypath/allData 的 javascript。但是此调用失败并出现 404 错误,页面永远找不到。我找不到为什么tomcat无法像Jetty那样解析路径的错误。
一旦战争在tomcat上工作。检查后这是在tomcat 9上。所以我在tomcat7上得到了错误,但不是9?我的服务器上安装的默认 tomcat 是 tomcat 7,因为我使用的是 synology nas。
谢谢你的帮助