博客
关于我
第八章、文件上传(二)(SpringBoot2.x)
阅读量:616 次
发布时间:2019-03-13

本文共 1037 字,大约阅读时间需要 3 分钟。

Spring Boot 2.x Jar包方式运行 Web 项目文件上传和访问


文件大小配置,在启动类中配置

在Spring Boot 2.x中,使用java -jar运行方式时,如果需要对文件上传的大小进行限制,可以在启动类中使用MultipartConfig进行配置。以下是一个常见配置示例:

@Beanpublic MultipartConfigElement multipartConfigElement() {    MultipartConfigFactory factory = new MultipartConfigFactory();    // 单个文件最大 10M    factory.setMaxFileSize(DataSize.of(10, DataUnit.MEGABYTES));    // 设置总上传数据总大小 1G    factory.setMaxRequestSize(DataSize.of(1, DataUnit.GIGABYTES));    return factory.createMultipartConfig();}

打包成 JAR 包,需要增加 Maven 依赖

在使用 java -jar 运行Spring Boot应用时,如果需要处理文件上传,通常需要使用Spring Boot Maven Plug-in来打包项目。需要注意的是,如果未添加相关依赖,打包完成后可能会报错提示“no main manifest attribute, in XXX.jar”。以下是配置依赖的 Maven 作业示例:

org.springframework.boot
spring-boot-maven-plugin

未添加相关依赖会导致错误

如果在项目中没有添加必要的Maven依赖,打包完成后运行时会抛出错误提示:“no main manifest attribute, in XXX.jar”。这个错误表明jar 包中缺少主版本文件,可能是由于spring-boot-maven-plugin未正确添加。


以上就是Spring Boot 2.x Jar包方式运行 Web 项目文件上传和访问的核心知识点。

转载地址:http://rddaz.baihongyu.com/

你可能感兴趣的文章
Nmap扫描教程之Nmap基础知识
查看>>
Nmap端口扫描工具Windows安装和命令大全(非常详细)零基础入门到精通,收藏这篇就够了
查看>>
NMAP网络扫描工具的安装与使用
查看>>
NMF(非负矩阵分解)
查看>>
NN&DL4.1 Deep L-layer neural network简介
查看>>
NN&DL4.3 Getting your matrix dimensions right
查看>>
NN&DL4.8 What does this have to do with the brain?
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>