Dropwizard表单MULTIPART - 启动时的资源抛出错误

时间:2015-04-23 22:00:25

标签: java intellij-idea jersey multipartform-data dropwizard

我试图在drop wizard 0.7.1中进行多部分文件上传工作。根据一个例子,我看到我添加了:

'io.dropwizard:dropwizard-forms:0.7.1',

到我的gradle文件。然后我创建以下资源:

    import com.path.to.service;
import com.sun.jersey.api.MessageException;
import com.sun.jersey.core.header.FormDataContentDisposition;
import com.sun.jersey.multipart.FormDataParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.*;

@Path("/api/v1/files")
@Api("/api/v1/files")
public class FileUploadResource {
    private static Logger logger = LoggerFactory.getLogger(FileUploadResource.class);
    private final MyService myService;

    public FileUploadResource(MyService myService) {
        this.myService = myService;
    }

    @POST
    @Path("/upload" )
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadFile(@FormDataParam("file") InputStream uploadedInputStream,
            @FormDataParam("file") FormDataContentDisposition fileDetail) throws MessageException, IOException {

        return myService.process(uploadedInputStream, fileDetail);
    }
}

我在主要应用程序中将资源添加到了jersey,就像我的其他资源一样:

MyService myService = new MyService();    
environment.jersey().register(new FileUploadResource(myService));

当我从IntelliJ启动应用程序时,我没有任何问题...我可以整天上传文件,没有任何错误或问题。但是,当我构建它并从命令行启动它时,启动时会出现运行时错误。我已经阅读了一些内容,我可能需要按类别注册资源,但在这种情况下,我不知道为什么它可以通过我的IDE工作。此外,对于'表格'以及它们在下拉向导0.7.x中的大量支持似乎也不像。模块。好像我错过了一些基本的东西。这是错误:

ERROR [2015-04-23 21:32:01,409] com.sun.jersey.spi.inject.Errors: The following errors and warnings have been detected with resource and/or provider classes:
  SEVERE: Missing dependency for method public int com.path.to.dropwizard.resources.FileUploadResource.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) throws java.io.IOException at parameter at index 0
  SEVERE: Missing dependency for method public int com.path.to.dropwizard.resources.FileUploadResource.uploadFile(java.io.InputStream,com.sun.jersey.core.header.FormDataContentDisposition) throws java.io.IOException at parameter at index 1
Exception in thread "main" javax.servlet.ServletException: com.sun.jersey.spi.container.servlet.ServletContainer-2c74ba35@9951d4d9==com.sun.jersey.spi.container.servlet.ServletContainer,1,false
        at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:561)
        at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:349)
        at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:812)
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:288)
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:732)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
        at com.codahale.metrics.jetty9.InstrumentedHandler.doStart(InstrumentedHandler.java:92)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
        at org.eclipse.jetty.server.handler.RequestLogHandler.doStart(RequestLogHandler.java:131)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
        at org.eclipse.jetty.server.handler.StatisticsHandler.doStart(StatisticsHandler.java:233)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
        at org.eclipse.jetty.server.Server.start(Server.java:342)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60)
        at org.eclipse.jetty.server.Server.doStart(Server.java:290)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
        at io.dropwizard.cli.ServerCommand.run(ServerCommand.java:43)
        at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:43)
        at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:76)
        at io.dropwizard.cli.Cli.run(Cli.java:70)
        at io.dropwizard.Application.run(Application.java:72)
        at com.path.to.dropwizard.application.FileRegistrationService.main(FileRegistrationService.java:50)
Caused by: com.sun.jersey.spi.inject.Errors$ErrorMessagesException
        at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
        at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
        at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
        at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
        at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
        at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
        at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
        at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
        at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
        at javax.servlet.GenericServlet.init(GenericServlet.java:244)
        at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:540)
        ... 36 more
WARN  [2015-04-23 21:32:01,412] /: unavailable
! com.sun.jersey.spi.inject.Errors$ErrorMessagesException: null
! at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at javax.servlet.GenericServlet.init(GenericServlet.java:244) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:540) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:349) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:812) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:288) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:732) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.codahale.metrics.jetty9.InstrumentedHandler.doStart(InstrumentedHandler.java:92) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.RequestLogHandler.doStart(RequestLogHandler.java:131) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.StatisticsHandler.doStart(StatisticsHandler.java:233) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.Server.start(Server.java:342) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:60) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.server.Server.doStart(Server.java:290) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at io.dropwizard.cli.ServerCommand.run(ServerCommand.java:43) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at io.dropwizard.cli.EnvironmentCommand.run(EnvironmentCommand.java:43) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:76) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at io.dropwizard.cli.Cli.run(Cli.java:70) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at io.dropwizard.Application.run(Application.java:72) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.path.to.dropwizard.application.FileRegistrationService.main(FileRegistrationService.java:50) [cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
WARN  [2015-04-23 21:32:01,414] org.eclipse.jetty.util.component.AbstractLifeCycle: FAILED i.d.j.MutableServletContextHandler@7d32391c{/,null,STARTING}: javax.servlet.ServletException: com.sun.jersey.spi.container.servlet.ServletContainer-2c74ba35@9951d4d9==com.sun.jersey.spi.container.servlet.ServletContainer,1,false
! com.sun.jersey.spi.inject.Errors$ErrorMessagesException: null
! at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at javax.servlet.GenericServlet.init(GenericServlet.java:244) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:540) ~[cdi-file-registration-service-dropwizard-1.0.2-SNAPSHOT.jar:na]
! ... 36 common frames omitted
! Causing: javax.servlet.ServletException: com.sun.jersey.spi.container.servlet.ServletContainer-2c74ba35@9951d4d9==com.sun.jersey.spi.container.servlet.ServletContainer,1,false

1 个答案:

答案 0 :(得分:0)

原来这是gradle插件阴影的一个问题,切换到另一个打包工具(使用不同的类加载器)立即解决了我的问题。