Home > Java > javaTutorial > How to Resolve 'No injection source found' Error in Jersey Multipart Form Data Upload?

How to Resolve 'No injection source found' Error in Jersey Multipart Form Data Upload?

Linda Hamilton
Release: 2024-12-12 15:26:13
Original
880 people have browsed it

How to Resolve

Multipart Form Data Injection Issue

Issue Description:

When attempting to upload files through a REST service using Jersey, the following error is encountered:

No injection source found for a parameter of type public javax.ws.rs.core.Response
Copy after login

Problem Analysis:

The error indicates that the Jersey multipart form data feature is not properly configured or the required JAR files are missing.

Solution:

1. Remove and Add Required JAR Files:

  • Remove the jersey-multipart-1.18.jar file, which is not compatible with Jersey 2.x.
  • Add the following two dependencies:

    • jersey-media-multipart-2.17
    • mimepull-1.9.3 (dependency pulled in by jersey-media-multipart)

2. Register MultiPartFeature:

  • Register the MultiPartFeature in your Jersey configuration:

    • ResourceConfig: register(MultiPartFeature.class);
    • web.xml:

      <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

3. Update Imported Classes:

  • After removing jersey-multipart-1.18.jar, there will be compile errors for missing imported classes. Update the class names to reflect the following changes:

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

The above is the detailed content of How to Resolve 'No injection source found' Error in Jersey Multipart Form Data Upload?. 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