Get rid of jersey-multipart-1.18.jar
. That is for Jersey 1.x. Add these two
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, semicolon, or space/newline. 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.
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…