Home > Java > javaTutorial > How to Resolve 'No ModelValidationException Found' Errors in Jersey File Uploads?

How to Resolve 'No ModelValidationException Found' Errors in Jersey File Uploads?

Susan Sarandon
Release: 2024-12-11 09:03:11
Original
310 people have browsed it

How to Resolve

MULTIPART_FORM_DATA: No ModelValidationException Found for a Parameter in UploadFileService

In Jersey-based RESTful service implementations for file uploads, you might encounter the error: "Validation of the application resource model has failed during application initialization. [[FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response."

To resolve this issue, you need to ensure that the correct JAR files are included in your project. Specifically:

  • Remove jersey-multipart-1.18.jar. It's for Jersey 1.x.
  • Add jersey-media-multipart-2.17 and mimepull-1.9.3.

For Maven, include the following dependency:

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-multipart</artifactId>
    <version>2.17</version>
</dependency>
Copy after login

Next, register the MultiPartFeature. If using ResourceConfig, register it as follows:

register(MultiPartFeature.class);
Copy after login

If using web.xml, add the class as an init-param to the Jersey servlet:

<init-param>
    <param-name>jersey.config.server.provider.classnames</param-name>
    <param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>
Copy after login

After resolving the JAR dependency issue, you may also encounter compile errors due to package changes in the imported classes. Ensure that the imported classes use the following packages:

  • org.glassfish.jersey.media.multipart.FormDataParam
  • org.glassfish.jersey.media.multipart.FormDataContentDisposition

By following these steps, you can resolve the MULTIPART_FORM_DATA error and successfully implement file uploads in your RESTful service using Jersey.

The above is the detailed content of How to Resolve 'No ModelValidationException Found' Errors in Jersey File Uploads?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template