【发布时间】:2016-04-28 12:42:58
【问题描述】:
我已经花了几个小时来解决以下问题:
我有一个带有以下 web.xml 的 Maven 项目
<?xml version="1.0" encoding="UTF-8"?>
<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_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>xy</display-name>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<!-- Auto scan REST service -->
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<!-- this should be the same URL pattern as the servlet-mapping property -->
<context-param>
<param-name>resteasy.servlet.mapping.prefix</param-name>
<param-value>/rest</param-value>
</context-param>
<listener>
<listener-class> org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
</servlet>
</web-app>
我的 Java 类如下所示:
@Path("/file")
public class File
{
@POST
@Path("/upload")
@Consumes("multipart/form-data")
public Response uploadFile(@MultipartForm Multipart form) {}
在 Project-> Run as -> Run on Server 之后会显示正确的 index.jsp。
当我点击一个上传文件的按钮时,我得到了错误:
HTTP 状态 404 - 找不到相关资源:/file/upload of full path: http://localhost:8080/Projectname/rest/file/upload
我做了什么:
- 清理项目
- 更新 Maven
- 运行方式 -> Maven -> 全新安装(构建成功)
- 删除 Tomcat 并重新安装
- 禁用自动扫描并手动添加“文件”
此外,我收到警告说在 Tomcat 路径 (/Tomcat8/wtpwebapps/Projectname/WEB-INF/lib/activation-1.1.jar (没有这样的文件或目录 - 但它在 pom 中可用) .xml 和 target->Projectname->WEB-INF->lib)
我使用的是resteasy-jaxrs 2.2.1.GA版
感谢您的帮助:)
【问题讨论】:
标签: maven tomcat pom.xml resteasy web.xml