MULTIPART_FORM_DATA: No injection source found for a parameter of type public javax.ws.rs.core.Response

Get rid of jersey-multipart-1.18.jar. That is for Jersey 1.x. Add these two

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

For Maven you would use the following dependency (you don't need to explicitly add the mimepull dependency, as this one will pull it in).

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-multipart</artifactId>
    <version>2.17</version> <!-- Make sure the Jersey version matches
                                 the one you are currently using -->
</dependency>

Then you need to register the MultiPartFeature. If you are using a ResourceConfig for configuration, you can simply do

register(MultiPartFeature.class);

If you are using web.xml, then you can 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>

Note that if you have multiple providers that you want to register, then you can delimit each provider class with a comma or semicolon. You cannot use this same param-name twice. See Suarabh's answer

UPDATE

Also, once you get rid of jersey-multipart-1.18.jar you will have compile errors for the missing imported classes. For the most part, the class names are still the same, just the packages have changed, i.e.

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

For Dropwizard

If you're using Dropwizard, instead of adding the jersey-media-multipart, they document for your to add dropwizard-forms instead. And instead of registering the MultiPartFeature, you should register the MultiPartBundle

@Override
public void initialize(Bootstrap<ExampleConfiguration> bootstrap) {
    bootstrap.addBundle(new MultiPartBundle());
}

Really doesn't make much difference though as all the Dropwizard bundle does is register the MultiPartFeature with the ResourceConfig.


Aside

If you are here for a different ModelValidationException, here are some links for information on other causes of the exception.

  • 1
  • 2
  • 3

Yet another possible cause for this very generic error is that Jersey only searches for factories associated with the last annotation when multiple ones are declared on a param. (See bug report)

Until this is fixed, if you are using any other annotations besides @FormDataParam, it has to come last.

This works:

@NotEmpty @FormDataParam("myParam") String myParam

This does not:

@FormDataParam("myParam") @NotEmpty String myParam

I too got the same exception.I did the following changes in web.xml

<init-param>
            <param-name>jersey.config.server.provider.classnames</param-name>
            <param-value>org.glassfish.jersey.filter.LoggingFilter;org.glassfish.jersey.moxy.json.MoxyFeature;org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
        </init-param>

and changed jersey 2.7 to 2.9 .I do not know what change of this 2 has solved the issue.