diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java index c4107dcd3c0..369d79162c0 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/MultipartAutoConfiguration.java @@ -16,9 +16,13 @@ package org.springframework.boot.autoconfigure.web; +import javax.servlet.MultipartConfigElement; +import javax.servlet.Servlet; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; import org.springframework.boot.context.embedded.MultipartConfigFactory; @@ -28,58 +32,55 @@ import org.springframework.context.annotation.Configuration; import org.springframework.util.StringUtils; import org.springframework.web.multipart.support.StandardServletMultipartResolver; -import javax.servlet.MultipartConfigElement; -import javax.servlet.Servlet; - /** * {@link EnableAutoConfiguration Auto-configuration} for multi-part uploads. Adds a * {@link StandardServletMultipartResolver} if none is present, and adds a - * {@link javax.servlet.MultipartConfigElement multipartConfigElement} if none is otherwise defined. - * The {@link EmbeddedWebApplicationContext} will associate the + * {@link javax.servlet.MultipartConfigElement multipartConfigElement} if none is + * otherwise defined. The {@link EmbeddedWebApplicationContext} will associate the * {@link MultipartConfigElement} bean to any {@link Servlet} beans. *
- * The {@link javax.servlet.MultipartConfigElement} is a Servlet API that's used to configure how the container handles - * file uploads. By default + * The {@link javax.servlet.MultipartConfigElement} is a Servlet API that's used to + * configure how the container handles file uploads. By default * * @author Greg Turnquist * @author Josh Long */ @Configuration -@ConditionalOnClass({Servlet.class, StandardServletMultipartResolver.class}) +@ConditionalOnClass({ Servlet.class, StandardServletMultipartResolver.class }) +@ConditionalOnExpression("${multipart.enabled:true}") @EnableConfigurationProperties(MultipartProperties.class) public class MultipartAutoConfiguration { - @Autowired - private MultipartProperties multipartProperties = new MultipartProperties(); + @Autowired + private MultipartProperties multipartProperties = new MultipartProperties(); - @Bean - @ConditionalOnMissingBean - public MultipartConfigElement multipartConfigElement() { - MultipartConfigFactory factory = new MultipartConfigFactory(); + @Bean + @ConditionalOnMissingBean + public MultipartConfigElement multipartConfigElement() { + MultipartConfigFactory factory = new MultipartConfigFactory(); - if (StringUtils.hasText(this.multipartProperties.getFileSizeThreshold())) { - factory.setFileSizeThreshold(this.multipartProperties.getFileSizeThreshold()); - } + if (StringUtils.hasText(this.multipartProperties.getFileSizeThreshold())) { + factory.setFileSizeThreshold(this.multipartProperties.getFileSizeThreshold()); + } - if (StringUtils.hasText(this.multipartProperties.getLocation())) { - factory.setLocation(this.multipartProperties.getLocation()); - } + if (StringUtils.hasText(this.multipartProperties.getLocation())) { + factory.setLocation(this.multipartProperties.getLocation()); + } - if (StringUtils.hasText(this.multipartProperties.getMaxRequestSize())) { - factory.setMaxRequestSize(this.multipartProperties.getMaxRequestSize()); - } + if (StringUtils.hasText(this.multipartProperties.getMaxRequestSize())) { + factory.setMaxRequestSize(this.multipartProperties.getMaxRequestSize()); + } - if (StringUtils.hasText(this.multipartProperties.getMaxFileSize())) { - factory.setMaxFileSize(this.multipartProperties.getMaxFileSize()); - } + if (StringUtils.hasText(this.multipartProperties.getMaxFileSize())) { + factory.setMaxFileSize(this.multipartProperties.getMaxFileSize()); + } - return factory.createMultipartConfig(); - } + return factory.createMultipartConfig(); + } - - @Bean - @ConditionalOnMissingBean - public StandardServletMultipartResolver multipartResolver() { - return new StandardServletMultipartResolver(); - } + @Bean + @ConditionalOnMissingBean + public StandardServletMultipartResolver multipartResolver() { + return new StandardServletMultipartResolver(); + } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/AutoConfigurationReportTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/AutoConfigurationReportTests.java index c3a4cc365e9..caf18c4e4cc 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/AutoConfigurationReportTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/AutoConfigurationReportTests.java @@ -37,9 +37,9 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Condition; import org.springframework.context.annotation.Import; -import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; @@ -211,7 +211,7 @@ public class AutoConfigurationReportTests { ConditionAndOutcomes outcomes = report.getConditionAndOutcomesBySource().get( autoconfigKey); assertThat(outcomes, not(nullValue())); - assertThat(getNumberOfOutcomes(outcomes), equalTo(1)); + assertThat(getNumberOfOutcomes(outcomes), equalTo(2)); List