美文网首页
解除Spring-Boot上传图片大小的限制

解除Spring-Boot上传图片大小的限制

作者: chuan_bai | 来源:发表于2017-08-26 21:06 被阅读210次
    • 由spring官方文档可知,spring-boot在MultipartProperties配置文件中对最大上传大小做了限制需要在启动时增加一个配置类
    • 在启动类里增加以下类即可解决问题
    /**
         * 解除上传文件的限制
         */
        @Configuration
        @ConditionalOnClass({Servlet.class, StandardServletMultipartResolver.class,
                MultipartConfigElement.class})
        @ConditionalOnProperty(prefix = "spring.http.multipart", name = "enabled", matchIfMissing = true)
        @EnableConfigurationProperties(MultipartProperties.class)
        public class MultipartAutoConfiguration {
    
            private final MultipartProperties multipartProperties;
    
            public MultipartAutoConfiguration(MultipartProperties multipartProperties) {
                this.multipartProperties = multipartProperties;
                multipartProperties.setMaxFileSize("-1");
            }
    
            @Bean
            @ConditionalOnMissingBean
            public MultipartConfigElement multipartConfigElement() {
                return this.multipartProperties.createMultipartConfig();
            }
    
            @Bean(name = DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME)
            @ConditionalOnMissingBean(MultipartResolver.class)
            public StandardServletMultipartResolver multipartResolver() {
                StandardServletMultipartResolver multipartResolver = new StandardServletMultipartResolver();
                multipartResolver.setResolveLazily(this.multipartProperties.isResolveLazily());
                return multipartResolver;
            }
    
        }
    

    以上参考springboot官方文档

    相关文章

      网友评论

          本文标题:解除Spring-Boot上传图片大小的限制

          本文链接:https://www.haomeiwen.com/subject/rcuvdxtx.html