Spring Boot doesn't use CommonsMultipartResolver? -
i have problem rest web service running spring boot (jetty). 1 of rest method file upload , i'm guessing commonsmultipartresolver not using during multipart requests.
signature of upload method :
@responsebody @requestmapping(value = "/upload", method = requestmethod.post, produces = "application/json") public baseresponse upload(@requestparam("login") string login, @requestparam("passwd") string passwd, @requestparam("partner") string partner, @requestparam("filename") string fname, @requestparam("length") int flen, @requestparam("file") multipartfile file) throws ioexception
i have root application class below :
@springbootapplication public class bootapplication { private static final logger _logger = logger.getlogger(bootapplication.class.getname()); public static void main(string[] args) { springapplication app = new springapplication(bootapplication.class, new classpathresource("web-inf/applicationcontext.xml"), new classpathresource("web-inf/dispatcher-servlet.xml")); app.run(args); } @bean(name = "multipartresolver") public commonsmultipartresolver multipartresolver(servletcontext servletcontext) { _logger.log(level.info, "[bootapplication] fetching commonsmultipartresolver"); return new commonsmultipartresolver(servletcontext); } }
when i'm calling method got error :
org.springframework.web.bind.missingservletrequestparameterexception: required multipartfile parameter 'file' not present @ org.springframework.web.method.annotation.requestparammethodargumentresolver.handlemissingvalue(requestparammethodargumentresolver.java:253) @ org.springframework.web.method.annotation.abstractnamedvaluemethodargumentresolver.resolveargument(abstractnamedvaluemethodargumentresolver.java:94) @ org.springframework.web.method.support.handlermethodargumentresolvercomposite.resolveargument(handlermethodargumentresolvercomposite.java:77) @ org.springframework.web.method.support.invocablehandlermethod.getmethodargumentvalues(invocablehandlermethod.java:162) @ org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:129) @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:110) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlemethod(requestmappinghandleradapter.java:776) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:705) @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:85) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:959) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:893) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:966) @ org.springframework.web.servlet.frameworkservlet.dopost(frameworkservlet.java:868) @ javax.servlet.http.httpservlet.service(httpservlet.java:707) @ org.springframework.web.servlet.frameworkservlet.service(frameworkservlet.java:842) @ javax.servlet.http.httpservlet.service(httpservlet.java:790) @ org.eclipse.jetty.servlet.servletholder.handle(servletholder.java:808) @ org.eclipse.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1669) @ org.eclipse.jetty.websocket.server.websocketupgradefilter.dofilter(websocketupgradefilter.java:224) @ org.eclipse.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1652) @ org.springframework.boot.actuate.autoconfigure.endpointwebmvcautoconfiguration$applicationcontextheaderfilter.dofilterinternal(endpointwebmvcautoconfiguration.java:295) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.eclipse.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1652) @ org.springframework.boot.actuate.trace.webrequesttracefilter.dofilterinternal(webrequesttracefilter.java:102) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.eclipse.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1652) @ org.springframework.web.filter.hiddenhttpmethodfilter.dofilterinternal(hiddenhttpmethodfilter.java:77) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.eclipse.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1652) @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:85) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.eclipse.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1652) @ org.springframework.boot.actuate.autoconfigure.metricsfilter.dofilterinternal(metricsfilter.java:68) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:107) @ org.eclipse.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1652) @ org.eclipse.jetty.servlet.servlethandler.dohandle(servlethandler.java:585) @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:143) @ org.eclipse.jetty.security.securityhandler.handle(securityhandler.java:577) @ org.eclipse.jetty.server.session.sessionhandler.dohandle(sessionhandler.java:223) @ org.eclipse.jetty.server.handler.contexthandler.dohandle(contexthandler.java:1127) @ org.eclipse.jetty.servlet.servlethandler.doscope(servlethandler.java:515) @ org.eclipse.jetty.server.session.sessionhandler.doscope(sessionhandler.java:185) @ org.eclipse.jetty.server.handler.contexthandler.doscope(contexthandler.java:1061) @ org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler.java:141) @ org.eclipse.jetty.server.handler.handlerwrapper.handle(handlerwrapper.java:97) @ org.eclipse.jetty.server.server.handle(server.java:497) @ org.eclipse.jetty.server.httpchannel.handle(httpchannel.java:310) @ org.eclipse.jetty.server.httpconnection.onfillable(httpconnection.java:257) @ org.eclipse.jetty.io.abstractconnection$2.run(abstractconnection.java:540) @ org.eclipse.jetty.util.thread.queuedthreadpool.runjob(queuedthreadpool.java:635) @ org.eclipse.jetty.util.thread.queuedthreadpool$3.run(queuedthreadpool.java:555) @ java.lang.thread.run(thread.java:745)
what's strange in stack trace cannot see commonsmultipartresolver
calls. thing same code working in glassfish environment - upload files no problem. changed multipartresolver
bean in glassfish defined in dispatcher-servlet.xml
, in spring boot initialize in bootapplication
class. tried left multipartresolver
in dispatcher-servlet.xml
i'm loading configuration none of solution worked.
when i'm looking @ /beans
endpoint in spring boot can see multipartresolver
bean. no other bean has dependency multipartresolver
bean - maybe wrong, have no idea how configure properly.
below have dispatcher-servlet.xml
if :
<?xml version="1.0" encoding="utf-8"?> <beans xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> <context:annotation-config /> <context:component-scan base-package="com.my.package" /> <mvc:annotation-driven /> </beans>
you using spring boot use it, trying work around it.
spring boot default configures file uploading can remove definition. if want control values can configure adding properties application.properties
. see this section of reference guide.
i suggest removing dispatcher-servlet.xml
because spring boot enables mvc configuration , enabling interferes auto configuration. assuming bootapplication
inside com.my.package
can remove file adds nothing, if bootapplication
in different package add @componentscan("com.my.package")
configuration.
to import applicationcontext.xml
add @importresource
bootapplication
instead of doing now. depending on in there (probably datasource, jpa, etc. configuration might remove , replace simple properties instead).
@springbootapplication @componentscan("com.my.package") @importresource("web-inf/applicationcontext.xml") public class bootapplication { public static void main(string[] args) throws exception { springapplication.run(bootapplication.class, args); } }
the main problem is disabling part of spring boot auto configuration let configure things.
Comments
Post a Comment