多部分、弹簧引导和 JBoss - 所需的请求部分"文件"不存在



我有一个应用程序,该应用程序使用 Spring-boot 和嵌入式 tomcat 进行开发,并且在生产服务器上已部署在 JBOSS 6.4 EAP 。添加了对JBOSS的支持后,Multipart文件上传停止工作。在两个容器上,它都在扔 MissingservletRequestPartException

多ArtipartConfigelement 添加到 servletRegistrationBean 修复了Tomcat上的此问题,但是对于JBOSS而言,它仍然无法正常工作。你有什么想法在哪里?

配置:

@Bean
public ServletRegistrationBean dispatcherRegistration(DispatcherServlet dispatcherServlet, MultipartConfigElement
        multipartConfig) {
    ServletRegistrationBean registration = new ServletRegistrationBean(dispatcherServlet);
    registration.getUrlMappings().clear();
    registration.addUrlMappings("/*");
    registration.setMultipartConfig(multipartConfig);
    return registration;
}

端点:

@RequestMapping(method = POST)
@ResponseBody
public SomeResponse uploadFileWithComment(
    @RequestParam(value = "file") final MultipartFile file,
    @RequestParam(value = "comment") String comment) {
    ...
}

web.xml

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>RestServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>com.rebelek.Application</param-value>
        </init-param>
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>
                org.springframework.web.context.support.AnnotationConfigWebApplicationContext
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>RestServlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

在此处讨论https://github.com/spring-projects/spring-boot/issues/2958建议如果您使用的是@EnableAutoConfiguration原因问题:

@EnableAutoConfiguration(exclude = {MultipartAutoConfiguration.class})

定义以下豆

@Bean(name = "multipartResolver") 
public CommonsMultipartResolver commonsMultipartResolver(){ 
CommonsMultipartResolver resolver = new CommonsMultipartResolver(); resolver.setMaxUploadSize(50*1024*1024); return resolver ; 
}

@Bean @Order(0) public MultipartFilter multipartFilter()
{ 
MultipartFilter multipartFilter = new MultipartFilter(); 
multipartFilter.setMultipartResolverBeanName("multipartResolver"); 
return multipartFilter; 
}

相关内容

  • 没有找到相关文章

最新更新