Springboot文件上传报错:failed to convert java.lang.String to org.springframework.util.unit.DataSize

配置文件报错 Cannot convert value of type ‘java.lang.String‘ to required type ‘javax.sql.DataSource‘ for p 问题 <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="myDataSource"/> <property name="configLocation" value="classpath:mybatis.xml"/> </bean> 中间的ref误用 阅读详情

springboot2.1.2版本文件上传报错,我上传的是一个18M的音频,默认的配置应该是超过10M的文件就会报错,所以我将配置修改为:

spring:
  servlet:
    multipart:
      enabled: true
      max-file-size: 100M
      max-request-size: 100M

但是启动的时候还是报错:

2019-01-20 01:43:31.982 ERROR 14632 — [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under ‘spring.servlet.multipart.max-file-size’ to org.springframework.util.unit.DataSize:
Property: spring.servlet.multipart.max-file-size
Value: 100M
Origin: class path resource [application.yml]:13:22
Reason: failed to convert java.lang.String to org.springframework.util.unit.DataSize

它的提示是org.springframework.util.unit.DataSize这个配置错误,我打开这个类,发现它的构造参数是一个long类型的数字:

private DataSize(long bytes) {
	this.bytes = bytes;
}

所以我修改了一下配置:

spring:
  servlet:
    multipart:
      enabled: true
      max-file-size: 100000000
      max-request-size: 100000000

将max-file-size和max-request-size都调整为数字的100000000,发现项目可以启动成功了,上传大文件也是正常的。我猜测应该是springboot将这个配置转换成数字类型时候出错了,不管是设置100M或者100000000L都无法从字符串直接转换成数字。


更新:
配置成100MB也是可以的,注意是大写字母MB

Springboot文件上传提示:failed to convert java.lang.String to org.springframework.util.unit.DataSize 场景 SpringBoot中通过配置文件限制上传文件的大小时配置 #设置单个文件上传的文件大小 spring.servlet.multipart.max-file-size=10Mb #设置所有文件上传的文件大小 spring.servlet.multipart.max-request-size=100Mb 提示: 解决 修改为: #设置单个文件上传的文件大小 sprin... 阅读详情

相关推荐

【异常】Spring Boot提示:Failed to convert from type [java.lang.String] to type [java.util.Date] for value

前后端分离项目,前端使用POST请求,将Date日期使用字符串String的类型传输给后端,后端加@RequestBody将JSON字符串,并将它转成对象。但是,报了如下错误。

奶爸的编程之路,也就一周冷个三天 3174

解决:SpringBoot2.x启动报failed to convert java.lang.String to org.springframework.util.unit.DataSize

1.错误描述 在application.yml配置文件中设置上传大小时,使用了Mb的单位 servlet: multipart: max-file-size: 10Mb max-request-size: 10Mb 然后启动报错: 二.问题排查解决 看提示是org.springframework.util.unit.DataSi...

guocunlei的博客 1万+

Simulink中通过MEX与MinGW实现C/C++结构体变量的高效导入

本文详细介绍了在Simulink中通过MEX工具链与MinGW编译器,高效导入C/C++结构体变量的完整流程。文章从需求背景出发,逐步讲解了MinGW环境配置、.h文件编写规范、核心导入命令Simulink.importExternalCTypes的使用,以及如何在MATLAB Function模块和总线创建器中调用自定义结构体,旨在实现模型与代码的无缝对齐,为后续仿真和代码生成奠定坚实基础。

weixin_29056781的博客 341

Failed to convert from type [java.lang.String] to type [@io.swagger.annotations.ApiParam @org.sprin

完整错误:Failed to convert from type [java.lang.String] to type [@io.swagger.annotations.ApiParam @org.springframework.web.bind.annotation.RequestParam java.util.Date 如果是请求参数,请加注解: @GetMapping(value = SUMMARY_URL, produces = "application/json") public Dail.

岸河世界 7745

OrangePi Kunpeng Pro 安装 ROS2 + Gazebo

OrangePi Kunpeng Pro 的优点很明显,内置openEuler,配备PD电源,做到开箱即用;板子设计也不错,风扇噪音不大,散热良好,昇腾芯片又确保小板子的性能,接口丰富是这类板子共同的优点,也很好的继承了下来,甚至还可以外接固态,可靠性大大提升。使用起来,哪怕不用openEuler的话,也可以很方便的刷Ubuntu来实现一些需要依赖的开发工作,这次没有跑AI模型,所以对算力的优势还没有很明显的感受,下次可以试一下yolo跑跑看。

Arcan 1822

经典密码体制(上)

头歌

shannidawang的博客 3086

SpingBoot2.x文件上传:failed to convert java.lang.String to org.springframework.util.unit.DataSize

问题现象: SpringBoot项目由1.5.x升级到2.x,文件上传启动报错 配置文件 #文件上传路径 linux配置路径 spring.servlet.multipart.max-file-size=50Mb spring.servlet.multipart.max-request-size=50Mb file.upload.realpath=D:/csizgcardmanage/...

琦彦 3782

1.Fay-UE5数字人工程导入(UE数字人系统教程)

ue5数字人系列教程(含源文件工程)

1万+

SpringBoot开发,常见的问题(1)

当使用springboot开发使用的时候,不想配置数据库配置的时候,启动类头部声明就可以了: @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class}) 当启动出现这个错误的时候 Failed to configure a DataSource: 'url' attribute is not specified and no embedd 原因可能是数据库连接没有配置,可以配置上对应的数据库链接信息,也可以使用这个

Mark的博客 358

Coze HTTP请求节点实战:5分钟搞定天气API对接(含动态参数技巧)

本文通过一个天气预报API对接的实战案例,详细讲解了如何在Coze平台使用HTTP请求节点实现外部数据交互。文章重点演示了动态参数传递、JSON响应解析与错误处理等核心技巧,帮助开发者在5分钟内快速构建稳定可靠的智能体外部服务调用能力。

weixin_29233333的博客 675

Star CCM+ 202206 (17.04) 详细安装步骤

StarCCM+ 17.04 安装包和详细安装步骤

薛定谔的alpha狗 3万+

failed to convert java.lang.String to org.springframework.util.unit.DataSize

问题描述: failed to convert java.lang.String to org.springframework.util.unit.DataSize Failed to bind properties under 'spring.servlet.multipart.max-request-size' to org.springframework.util.unit.DataSize: Property: spring.servlet.multipart.max-request-si

qq_45283095的博客 1999

对halcon形状匹配算法的一点分析

基于Intel VTune Profiler对halcon形状匹配算法的一点分析

manuoo的专栏 566

org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.S

插入数据时,未指定id,自动生成的id=“FCHWzYgBjGsveCR9T0T0”是一个字符串,而自定义的id是long类型,无法转换,查询时报错。使用Elasticsearch查询全部时报错。

qq_45875887的博客 1742

AI编码规则:从提示工程到自动化,提升大模型生成代码质量

在软件工程领域,代码质量是保障软件可维护性、安全性和团队协作效率的核心。其背后遵循着从基础语法规范到架构设计原则的一系列工程实践。随着大语言模型(LLM)在代码生成任务中的广泛应用,如何确保AI生成的代码符合这些工程标准,成为一个关键的技术挑战。这涉及到将人类工程师积累的最佳实践,转化为机器可理解、可执行的明确约束。通过系统化的**编码规则**定义与集成,例如构建涵盖安全、风格、架构的多层次规则集,并将其融入**提示工程**或自动化工作流,可以显著引导AI产出更健壮、规范的代码。这种方法的价值在于,它能将模

weixin_42525189的博客 641

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

关于spring配置中datasource的问题‘java.lang.String‘ to required type ‘javax.sql.DataSource‘

关于spring中的convert value of type [java.lang.String] to required type [javax.sql.DataSource]问题。 无法将你的datasource里配置的字符串转换成javax.sql.DataSource对象,导致SessionFactory无法完成,datasource配置肯定有误,检查[/WEB-INF/applicationContext.xml]文件中的datasource相关的配置。或者贴出来让大家看看。 <prop

Canner_的博客 1894

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

解决:Failed to convert from type [java.lang.String] to type [java.sql.Date]

【代码】解决:Failed to convert from type [java.lang.String] to type [java.sql.Date]

我现在难受的一批的博客 3447

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Spring Boot 集成 MongoDB读取数据出现Failed to convert from type [java.lang.String] to type [java.util.Date]

这样就可以解决 Failed to convert from type [java.lang.String] to type [java.util.Date] 问题 spring 的Converter 类很强大 在spring mvc 中也可以添加自定义转化器。这个就是MongoDB弱类型导致的 可能是有用户很老的数据存在格式问题导致 spring model 映射不上 ,解决这个就又2个方法 1是找出这些数据删除 2是为MongoDB添加一个转化器 ,我选择转化器 删除旧数据治标不治本开搞。

weng74的博客 3354

RepositoryRestExceptionHandler : Failed to convert from type [java.lang.String] to type [java.lang.L

this.$http.get('/rest/ApisService/search/findByClusterId', { params: { clusterId: clusterId } }).then((response) => {}) @RepositoryRestResource(collectionResourceRel = "ApisService", path = "ApisService") public interface ApisServiceReposi.

cry1049208942的专栏 1075

Failed to convert from type [java.lang.String] to type [@javax.persistence.Transient java.util.Date]

Failed to convert from type [java.lang.String] to type [@javax.persistence.Transient java.util.Date] for value ‘2020-08-23’ 原因:springboot可以自动识别yyyy/MM/dd格式的时间字符串并注入Date类型的属性中,但不能识别yyyy-MM-dd等格式的字符串 解决方法:在属性上标注传入的格式 @DateTimeFormat(pattern = "yyyy-MM-dd") p

jerry_wzj_的博客 4715

【踩坑日常,已解决】Failed to convert from type [java.lang.String] to type [java.util.Date]

解决报错:Failedtoconvertfromtype[java.lang.String]totype[java.util.Date]

Sao_E的博客 1479

Failed to convert value of type ‘java.lang.String‘ to required type ‘java.lang.Long‘总是说请求参数类型错误

原因在businessPaymentBatch这个类我没有写getUserPostCode这个接口,由于我在前端写的请求是GET请求,所以后台就直接去找businessPaymentBatch里面的GET接口,而这个接口又是PathVariable的,所以就直接把我的 "getUserPostCode"接口名去代替PathVariable路径了,所以总是说我String 不能转 Long,需要的参数是Long类型,但你却给了String类型。他不给我报错404,居然是给我报错类型转换错误。

qq_44627822的博客 4万+

java.lang.ClassNotFoundException: org.springframework.util.unit.DataSize

spring boot 启动报错。 Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/util/unit/DataSize at org.springframework.boot.convert.StringToDataSizeConverter.getConvertibleTypes(S...

城里俊男多博客 2万+

Spring表单提交日期类型绑定Failed to convert from type java.lang.String to type java.util.D

  org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type java.util.Date   解决Spring自动绑定中的数据转换问题,直接在Controller中添加下面一段代码即可,其他数据类型同理。   ...

鬼烧java 1275

springboot启动报错:java.lang.NoClassDefFoundError: org/springframework/util/unit/DataSize

启动springboot时报错,错误提示如下: java.lang.NoClassDefFoundError: org/springframework/util/unit/DataSize at org.springframework.boot.convert.StringToDataSizeConverter.getConvertibleTypes(StringToDataSizeC...

zangqijie123的博客 2万+

Failed to convert from type java.lang.String to type java.util.Date for value ‘2017-12-06‘;

报错: org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type java.util.Date for value ‘2017-12-06‘; nested exception is java.lang.IllegalArgumentException] 解决办法: 在pojo的属性上加注解 @DateTimeFormat(patt

DREGON_的博客 671
上一篇: SpringBoot集成swagger-ui以及swagger分组显示
下一篇: SpringBoot Aop入门
程序员青戈
程序员青戈 领域专家: 后端开发技术领域 领域专家: 后端开发技术领域
博客等级 码龄10年 3万+粉丝 250原创
评论 8
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员青戈

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值