2016-04-28 54 views
0

我已經花了幾個小時就解決以下問題:HTTP狀態404 - 找不到相關的資源:完整路徑:的RESTEasy

我有一個Maven項目具有以下的web.xml

<?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) {} 

後項目 - >運行方式 - >服務器上運行顯示正確的index.jsp。

當我點擊一個按鈕,上傳文件出現錯誤:

HTTP狀態404 - 相對找不到資源:/文件/上傳完整路徑:http://localhost:8080/Projectname/rest/file/upload

我已位於做到:

  • 清潔工程
  • 更新的Maven
  • 運行方式 - > Maven的 - >全新安裝(建sucess)
  • 刪除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

我很感激任何幫助:)

回答

0

請嘗試以下幾點。

  1. 嘗試在web.xml中添加軟件包名稱,以便輕鬆掃描JAX-RS註釋的類文件。結帳scan resteasy resources by package name
  2. 確保在調用REST端點時設置正確的Content-Type。即,多部分/表格數據