1,..\web\src\main\resources\spring\web-men-applicationContext.xml

保留原有的bean配置

<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- set the max upload size100MB -->
<property name="maxUploadSize">
<value>104857600</value>
</property>
</bean>

2,..\web\WebApplication.java
之前调试过程中,配置了本地bean信息,最终还是删除了,因为无法解决自己加目录/tmp问题
/**
* spring boot统一入口
*/
@ImportResource({"classpath:spring/web-men-applicationContext.xml"})
public class WebApplication extends MobileBaseApplication {

public static void main(String[] args) {
final ConfigurableApplicationContext context = SpringApplication.run(WebApplication.class, args);
}

@Bean
public FilterRegistrationBean characterEncodingfilter() {
OrderedCharacterEncodingFilter filter = new OrderedCharacterEncodingFilter();
filter.setEncoding("UTF-8");
filter.setForceEncoding(true);
filter.setForceRequestEncoding(true);
filter.setForceResponseEncoding(true);
FilterRegistrationBean registration = new FilterRegistrationBean(filter);
registration.addUrlPatterns("/*");
return registration;
}

@Bean
public FilterRegistrationBean corsFilterRegistration() {
CorsInterceptor filter = new CorsInterceptor();
FilterRegistrationBean registration = new FilterRegistrationBean(filter);
registration.setName("corsFilter");
registration.addUrlPatterns("/*");
return registration;
}

/**
* 文件上传配置-----最终还是去掉了
*/
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
//单个文件最大
factory.setMaxFileSize("10240KB"); //KB,MB
/// 设置总上传数据总大小
factory.setMaxRequestSize("102400KB");
factory.setLocation("");
return factory.createMultipartConfig();
}

3,最终解决方式为:springboot基类中,
@EnableAutoConfiguration注解exclude里排除springboot自带的bean
MultipartAutoConfiguration.class

..\common\util\MobileBaseApplication.java

@Configuration
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class
, DataSourceTransactionManagerAutoConfiguration.class, JndiDataSourceAutoConfiguration.class,
XADataSourceAutoConfiguration.class,MultipartAutoConfiguration.class})
public abstract class MobileBaseApplication extends QggBaseApplication {

}


下面来文字描述下问题的出现和解决思路:
1,@RequestParam("uploadFile") MultipartFile[] files,controller中files的size为0了。
解决方法:
移出掉web-men-applicationContext.xml中的
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- set the max upload size100MB -->
<property name="maxUploadSize">
<value>104857600</value>
</property>
</bean>
,这样就用org.springframework.web.multipart.support包下的transferTo方法,而不是原有自己配置的bean里org.springframework.web.multipart.commons包下的transferTo方法了。

但这引发了另外一个问题,上传文件的目录前被加了个/tmp目录,导致文件上传找不到真实路径。
最终write方法看到是org.eclipse.jetty.util包下MultiPartInputStreamParser类下的属性值 protected File _tmpDir;
this._file = new File(MultiPartInputStreamParser.this._tmpDir, fileName);
由于这么个东西的存在,决定把SpringBoot的统一入口中(WebApplication.java),添加bean,让spring初始化的时候去获取这个bean
/**
* 文件上传配置
*/
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
//单个文件最大
factory.setMaxFileSize("10240KB"); //KB,MB
/// 设置总上传数据总大小
factory.setMaxRequestSize("102400KB");
factory.setLocation("");
return factory.createMultipartConfig();
}

但是还是不行,依然有/tmp出现,debug看到
MultiPartInputStreamParser.class下的parse()方法里this._tmpDir还是会被设置上默认值:
if (this._config.getLocation() == null) {
this._tmpDir = this._contextTmpDir;
} else if ("".equals(this._config.getLocation())) {
this._tmpDir = this._contextTmpDir;
} else {
File f = new File(this._config.getLocation());
if (f.isAbsolute()) {
this._tmpDir = f;
} else {
this._tmpDir = new File(this._contextTmpDir, this._config.getLocation());
}
}

因此认为,不能再让上传文件的transferTo再走到MultiPartInputStreamParser里面。
那么就还是要自己配置bean,而不是走springboot默认的配置。
所以把一切之前的针对文件上传改动还原到springboot升级之前。

要排除掉springboot的自动ioc,..\common.util\MobileBaseApplication.java
@Configuration
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class
, DataSourceTransactionManagerAutoConfiguration.class, JndiDataSourceAutoConfiguration.class,
XADataSourceAutoConfiguration.class,MultipartAutoConfiguration.class})
public abstract class MobileBaseApplication extends QggBaseApplication {

}
 




springboot升级导致文件上传自动配置/tmp目录问题解决的更多相关文章

  1. SpringBoot项目实现文件上传和邮件发送

    前言 本篇文章主要介绍的是SpringBoot项目实现文件上传和邮件发送的功能. SpringBoot 文件上传 说明:如果想直接获取工程那么可以直接跳到底部,通过链接下载工程代码. 开发准备 环境要 ...

  2. [转]ExtJs入门之filefield:文件上传的配置+结合Ajax完美实现文件上传的asp.net示例

    原文地址:http://www.stepday.com/topic/?459 作文一个ExtJs的入门汉子,学习起来的确是比较费劲的事情,不过如今在这样一个网络资源如此丰富的时代,依然不是那么难了的. ...

  3. Springboot如何启用文件上传功能

    网上的文章在写 "springboot文件上传" 时,都让你加上模版引擎,我只想说,我用不上,加模版引擎,你是觉得我脑子坏了,还是觉得我拿不动刀了. springboot如何启用文 ...

  4. springboot 文件上传大小配置

    转自:https://blog.csdn.net/shi0299/article/details/69525848 springboot上传文件大小的配置有两种,一种是设置在配置文件里只有两行代码,一 ...

  5. SpringBoot之GZip压缩,HTTP/2,文件上传,缓存配置

    1 设置应用端口以及context # HTTP Server port server.port=8080 # Make the application accessible on the given ...

  6. SpringBoot+BootStrap多文件上传到本地

    1.application.yml文件配置 # 文件大小 MB必须大写 # maxFileSize 是单个文件大小 # maxRequestSize是设置总上传的数据大小 spring: servle ...

  7. asp.net文件/大文件上传需要配置的项目整理

    HTTP 错误 404.13 - Not Found 请求筛选模块被配置为拒绝超过请求内容长度的请求. 最可能的原因: •Web 服务器上的请求筛选被配置为拒绝该请求,因为内容长度超过配置的值. 可尝 ...

  8. php文件上传参考配置与大文件上传

      PHP用超级全局变量数组$_FILES来记录文件上传相关信息的,在php文件上传之前,可通过调节php.ini中相关配置指令,来控制上传相关细节. 1.file_uploads=on/off   ...

  9. WebService文件上传相关配置(404.13、超出限制、超时)

    最近在做文件上传的功能,遇到一些问题,记录如下,以备以后使用. 1.HTTP Error 404.13 - Not Found,请求筛选模块被配置为拒绝超过请求内容长度的请求. IIS默认允许请求长度 ...

随机推荐

  1. 快速解读linq语法

    在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之前, 我们在声明一个变量的时候, 总是要为一个变量指定他的类型 甚至在fore ...

  2. sublime破解 mac版本下载

    date: "2020-10-18T10:03:01+08:00" title: "sublime破解 mac版本下载" tags: ["sublim ...

  3. lumen-ioc容器测试 (2)

    lumen-ioc容器测试 (1) lumen-ioc容器测试 (2) lumen-ioc容器测试 (3) lumen-ioc容器测试 (4) lumen-ioc容器测试 (5) lumen-ioc容 ...

  4. spring boot: 从配置文件中读取数据的常用方法(spring boot 2.3.4)

    一,从配置文件中读取数据有哪些方法? 通常有3种用法: 1,直接使用value注解引用得到配置项的值 2,  封装到Component类中再调用 3,  用Environment类从代码中直接访问 生 ...

  5. php-fpm 高并发 参数调整 转

    工作中经常会遇到会给客户配置服务器,其中有的客户还会有并发量要求,其中也会必须要用负载均衡承载压力的.增加服务器数量肯定能有效的提升服务器承载能力,但只有根据目前已有配置设置好单台服务器才能更好的发挥 ...

  6. go内建方法 make方法

    package main import "fmt" func main() { // make函数 makeSlice() // 创建切片 makeMap() // 创建集合 ma ...

  7. lumen 添加配置

    app同级目录新建config目录 添加配置文件 bootstrap/app.php里面加载 $app->configure('options');使用 $router->get('/', ...

  8. Python中while循环初识

    基本结构 ​ while 条件: ​ 循环体 基本原理: ​ 1.先判断条件是否为True ​ 2.如果是True进入循环体 ​ 3.执行到循环体的底部 ​ 4.继续判断条件,条件为True,再次进入 ...

  9. 安卓日常开发和逆向中常用的shell命令与非shell命令

    简述shell 命令与 非shell命令区别 shell命令不用先adb shell进入界面执行 非shell命令必须要 adb shell进入界面执行 基础非shell命令 1.安装app adb ...

  10. C# 实现十六进制Unicode编码字符串转换为汉字

    网上找了几个方法,但是运行之后会报错,提示要解析的字符串格式不正确.然后我猜想可能是传入的字符串 \u60a8\u4eca\u65e5\u5df2\u7b7e\u5230 中带"\" ...