java – Initialization failure on JAXRS Jersey SpringBoot REST API

A simple image upload controller consuming multipart/form-data fails to initialize.

The controller code

    @POST
    @Path("/image")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(MediaType.APPLICATION_JSON)
    public Response uploadImage( @FormDataParam("image") InputStream fileInputStream )
            throws Exception{

        BufferedImage image = ImageIO.read(fileInputStream);
        System.out.println("uploaded image");

        return Response.ok("done").build();
    }

https://github.com/snambi/jersey-server/blob/master/src/main/java/org/github/api/test/jerseyserver/ImageController.java

Error happens during the first request when Jersey is initializing the controller.

org.glassfish.jersey.server.model.ModelValidationException: 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 org.github.api.test.jerseyserver.ImageController.uploadImage(java.io.InputStream) throws java.lang.Exception at index 0.; source="ResourceMethod{httpMethod=POST, consumedTypes=[multipart/form-data], producedTypes=[application/json], suspended=false, suspendTimeout=0, suspendTimeoutUnit=MILLISECONDS, invocable=Invocable{handler=ClassBasedMethodHandler{handlerClass=class org.github.api.test.jerseyserver.ImageController, handlerConstructors=[org.glassfish.jersey.server.model.HandlerConstructor@7515f97e]}, definitionMethod=public javax.ws.rs.core.Response org.github.api.test.jerseyserver.ImageController.uploadImage(java.io.InputStream) throws java.lang.Exception, parameters=[Parameter [type=class java.io.InputStream, source=image, defaultValue=null]], responseType=class javax.ws.rs.core.Response}, nameBindings=[]}"]
    at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:375) ~[jersey-server-2.35.jar:na]
    at org.glassfish.jersey.server.ApplicationHandler.lambda$initialize$1(ApplicationHandler.java:297) ~[jersey-server-2.35.jar:na]
    at org.glassfish.jersey.internal.Errors.process(Errors.java:292) ~[jersey-common-2.35.jar:na]
    at org.glassfish.jersey.internal.Errors.process(Errors.java:274) ~[jersey-common-2.35.jar:na]
    at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:232) ~[jersey-common-2.35.jar:na]
    at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:296) ~[jersey-server-2.35.jar:na]
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:261) ~[jersey-server-2.35.jar:na]
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311) ~[jersey-container-servlet-core-2.35.jar:na]
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:154) ~[jersey-container-servlet-core-2.35.jar:na]
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:347) ~[jersey-container-servlet-core-2.35.jar:na]
    at javax.servlet.GenericServlet.init(GenericServlet.java:158) ~[tomcat-embed-core-9.0.62.jar:4.0.FR]
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1164) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:804) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:128) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.62.jar:9.0.62]
    at java.base/java.lang.Thread.run(Thread.java:829) ~[na:na]

Seems like some configuration or dependencies are missing. Anyone else facing this issue and found a solution?

The source code is found at https://github.com/snambi/jersey-server

Leave a Comment