diff --git a/spring-boot-project/spring-boot-autoconfigure/pom.xml b/spring-boot-project/spring-boot-autoconfigure/pom.xml index 5d10f20196..a9a373d675 100755 --- a/spring-boot-project/spring-boot-autoconfigure/pom.xml +++ b/spring-boot-project/spring-boot-autoconfigure/pom.xml @@ -695,6 +695,11 @@ logback-classic test + + commons-fileupload + commons-fileupload + test + com.atomikos transactions-jms diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfiguration.java index 1cc9d28474..57d8375226 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ import org.springframework.boot.web.servlet.context.ServletWebServerApplicationC import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.multipart.MultipartResolver; +import org.springframework.web.multipart.commons.CommonsMultipartResolver; import org.springframework.web.multipart.support.StandardServletMultipartResolver; import org.springframework.web.servlet.DispatcherServlet; @@ -62,7 +63,8 @@ public class MultipartAutoConfiguration { } @Bean - @ConditionalOnMissingBean + @ConditionalOnMissingBean({ MultipartConfigElement.class, + CommonsMultipartResolver.class }) public MultipartConfigElement multipartConfigElement() { return this.multipartProperties.createMultipartConfig(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfigurationTests.java index 978193ef40..50a20e59b9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/MultipartAutoConfigurationTests.java @@ -44,6 +44,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartResolver; +import org.springframework.web.multipart.commons.CommonsMultipartResolver; import org.springframework.web.multipart.support.StandardServletMultipartResolver; import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.config.annotation.EnableWebMvc; @@ -184,6 +185,17 @@ public class MultipartAutoConfigurationTests { .getBean(MultipartResolver.class); assertThat(multipartResolver) .isNotInstanceOf(StandardServletMultipartResolver.class); + assertThat(this.context.getBeansOfType(MultipartConfigElement.class)).hasSize(1); + } + + @Test + public void containerWithCommonsMultipartResolver() throws Exception { + this.context = new AnnotationConfigServletWebServerApplicationContext( + ContainerWithCommonsMultipartResolver.class, BaseConfiguration.class); + MultipartResolver multipartResolver = this.context + .getBean(MultipartResolver.class); + assertThat(multipartResolver).isInstanceOf(CommonsMultipartResolver.class); + assertThat(this.context.getBeansOfType(MultipartConfigElement.class)).hasSize(0); } @Test @@ -351,6 +363,15 @@ public class MultipartAutoConfigurationTests { } + public static class ContainerWithCommonsMultipartResolver { + + @Bean + CommonsMultipartResolver multipartResolver() { + return mock(CommonsMultipartResolver.class); + } + + } + @Controller public static class WebController { diff --git a/spring-boot-project/spring-boot-parent/pom.xml b/spring-boot-project/spring-boot-parent/pom.xml index 318033ff1e..b8461d103d 100644 --- a/spring-boot-project/spring-boot-parent/pom.xml +++ b/spring-boot-project/spring-boot-parent/pom.xml @@ -54,6 +54,11 @@ log4j 1.2.17 + + commons-fileupload + commons-fileupload + 1.3.3 + com.nhaarman mockito-kotlin