Home >Java >javaTutorial >How to Solve 'No injection source found' Errors in Jersey Multipart File Uploads?

How to Solve 'No injection source found' Errors in Jersey Multipart File Uploads?

DDD
DDDOriginal
2024-12-08 14:47:10182browse

How to Solve

Multipart File Upload Issues with Jersey Restful API

In an effort to create a RESTful service for file uploads, you encountered the error: "No injection source found for a parameter of type public javax.ws.rs.core.Response." This error arises after attempting to run your Tomcat server.

Solution:

Your current dependencies include jersey-multipart-1.18.jar, which is meant for Jersey 1.x. For a successful build, replace it with these two JARs:

  • jersey-media-multipart-2.17
  • mimepull-1.9.3

Additionally, register the MultiPartFeature class to your application. If using ResourceConfig, simply invoke:

register(MultiPartFeature.class);

For web.xml configuration, add the following 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>

After removing jersey-multipart-1.18.jar, you may encounter compile errors due to modified package names. Specifically, the following package names have changed:

  • FileUploadHandler -> org.glassfish.jersey.media.multipart
  • MultiPartFeature -> org.glassfish.jersey.media.multipart
  • FormDataParam -> org.glassfish.jersey.media.multipart
  • FormDataContentDisposition -> org.glassfish.jersey.media.multipart

Update your code accordingly, and your file upload service should operate as intended.

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

Statement:
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