问题描述

在升级Java Azure Blob Storage SDK的过程中,先后遇见了 UnsatisfiedDependencyException 和 UnexpectedLengthException.

错误一:Org.springframework.beans.factory UnsatisfiedDependencyException: Error creating bean with name 'azureFileServiceImpl': Unsatisfied dependency expressed through field 'blobServiceClient'.

错误二:com.azure.core.exception UnexpectedLengthException Request body emitted 27183 bytes, less than the expected 31671447552 bytes.

问题解答

对于问题一:UnsatisfiedDependencyException  错误,一般来说,都是应用中引入包的版本不兼容导致,最好的办法就是升级到当前最新的版本。如把 springboot 版本升级到了2.5.6,azure storage blob版本升级到12.13.0。

但当问题一解决后,引发了问题二:com.azure.core.exception UnexpectedLengthException Request body emitted 27183 bytes, less than the expected 31671447552 bytes。

经过对代码中涉及到 File Length, Size等代码的调试后,发现问题所在:Azure storage Blob 由12.4.0升级到12.13.0后,获取文件的 length 发生了变化。

由旧版本的 file对象的 getTotalSpace()  变为 FileInputstream对象的 available() 。 

代码改动截图如下:

附录一:UploadExportFile 完整代码

@Service
public class AzureServiceImpl implements AzureService{ @Autowired
private BlobServiceClient blobServiceClient; @Autowired
private SysResourceMapper sysResourceMapper; @Autowired
private SysOfflineExportMapper sysOfflineExportMapper; @Autowired
private SysOfflineExportService sysOfflineExportService; @Override
public boolean uploadExportFile(File file, SysOfflineExport export) {
BlobContainerClient blobContainerClient = blobServiceClient.getBlobContainerClient("uploadblobdata");
if(!blobContainerClient.exists()){
createBlobContainer();
}
FileInputStream fileInputStream;
try {
fileInputStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
export.setLog(e.getMessage());
export.setStatus(OperationStatus.Done);
export.setResultType(ResultType.Failed);
sysOfflineExportService.updateByUuid(export);
return false;
}
//long size = file.getTotalSpace();
long size = fileInputStream.available();
String fileName = export.getFilenames();
BlobClient blobClient = blobContainerClient.getBlobClient(fileName);
blobClient.upload(fileInputStream,size);
String blobUrl = blobClient.getBlobUrl();
export.setDownloadurl(blobUrl);
sysOfflineExportService.updateByUuid(export);
if(StringUtils.isNotBlank(blobUrl)){
export.setStatus(OperationStatus.Done);
export.setResultType(ResultType.Success);
sysOfflineExportService.updateByUuid(export);
return true;
}
export.setStatus(OperationStatus.Done);
export.setLog("upload file to blob failed!");
sysOfflineExportService.updateByUuid(export);
return false;
} }

【Azure 存储服务】Azure Blob Storage SDK 升级失败,遇见 Unsatisfied Dependency Exception 和 Unexpected Length Exception的更多相关文章

  1. 【Azure 存储服务】代码版 Azure Storage Blob 生成 SAS (Shared Access Signature: 共享访问签名)

    问题描述 在使用Azure存储服务,为了有效的保护Storage的Access Keys.可以使用另一种授权方式访问资源(Shared Access Signature: 共享访问签名), 它的好处可 ...

  2. 【Azure 存储服务】.NET7.0 示例代码之上传大文件到Azure Storage Blob

    问题描述 在使用Azure的存储服务时候,如果上传的文件大于了100MB, 1GB的情况下,如何上传呢? 问题解答 使用Azure存储服务时,如果要上传文件到Azure Blob,有很多种工具可以实现 ...

  3. 玩转Windows Azure存储服务——网盘

    存储服务是除了计算服务之外最重要的云服务之一.说到云存储,大家可以想到很多产品,例如:AWS S3,Google Drive,百度云盘...而在Windows Azure中,存储服务却是在默默无闻的工 ...

  4. 解读 Windows Azure 存储服务的账单 – 带宽、事务数量,以及容量

    经常有人询问我们,如何估算 Windows Azure 存储服务的成本,以便了解如何更好地构建一个经济有效的应用程序.本文我们将从带宽.事务数量,以及容量这三种存储成本的角度探讨这一问题. 在使用 W ...

  5. 对象存储服务(Object Storage Service,简称 OSS)

    阿里云对象存储服务(Object Storage Service,简称 OSS),是阿里云提供的海量.安全.低成本.高可靠的云存储服务.它具有与平台无关的RESTful API接口,能够提供99.99 ...

  6. 【Azure 存储服务】Java Azure Storage SDK V12使用Endpoint连接Blob Service遇见 The Azure Storage endpoint url is malformed

    问题描述 使用Azure Storage Account的共享访问签名(Share Access Signature) 生成的终结点,连接时遇见  The Azure Storage endpoint ...

  7. 【Azure 存储服务】Python模块(azure.cosmosdb.table)直接对表存储(Storage Account Table)做操作示例

    什么是表存储 Azure 表存储是一项用于在云中存储结构化 NoSQL 数据的服务,通过无结构化的设计提供键/属性存储. 因为表存储无固定的数据结构要求,因此可以很容易地随着应用程序需求的发展使数据适 ...

  8. 【Azure 存储服务】如何把开启NFS 3.0协议的Azure Blob挂载在Linux VM中呢?(NFS: Network File System 网络文件系统)

    问题描述 如何把开启NFS协议的Azure Blob挂载到Linux虚拟机中呢? [答案]:可以使用 NFS 3.0 协议从基于 Linux 的 Azure 虚拟机 (VM) 或在本地运行的 Linu ...

  9. Windows Azure入门教学:使用Blob Storage

    对于.net开发人员,这是一个新的领域,但是并不困难.本文将会介绍如何使用Blob Storage.Blob Storage可以看做是云端的文件系统.与桌面操作系统上不同,我们是通过REST API来 ...

  10. 玩转Windows Azure存储服务——高级存储

    在上一篇我们把Windows Azure的存储服务用作网盘,本篇我们继续挖掘Windows Azure的存储服务——高级存储.高级存储自然要比普通存储高大上的,因为高级存储是SSD存储!其吞吐量和IO ...

随机推荐

  1. top的简单学习

    获取当前进程的全部线程 jps 获取jvm的进程信息. top -Hp $pid -bn 1 > 1.txt 可以获取当前特定进程的所有子进程. 注意linux与Windows的不太一样. li ...

  2. v-for动态添加表单,并且获取表单中的值

    vue是数据驱动视图,所以要想改变页面的结构,就要首先改变数据. 要想动态添加一个input表单,每当你点击的时候,添加一个数据在数组里面. handler(mess){ this.list.push ...

  3. TienChin 活动管理-删除活动

    后端 ActivityController.java @PreAuthorize("hasPermission('tienchin:activity:remove')") @Log ...

  4. springboot多模块打包报错问题根因分析:Unable to find main class

    问题背景: 项目结构为springboot多模块,其中有四个模块bean.utils.user.ems,其中user和ems模块为主程序,包含启动类,其他两个模块为其服务,提供依赖 问题分析: 查看u ...

  5. 用python进行精细中文分句(基于正则表达式),HarvestText:文本挖掘和预处理工具

    1.用python进行精细中文分句(基于正则表达式) 中文分句,乍一看是一个挺简单的工作,一般我们只要找到一个[.!?]这类的典型断句符断开就可以了吗.       对于简单的文本这个做法是已经可行了 ...

  6. Redis 数据库配置与应用

    Redis 是一个key-value存储系统.Redis是一个开源的使用ANSI C语言编写.遵守BSD协议.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. ...

  7. C/C++ 操作数组与指针笔记

    指针数组: #include <stdio.h> #include <stdlib.h> #include <string.h> void PrintInt() { ...

  8. Python常用脚本-查询数据库,调用网站接口,下载文件保存到本地

    # coding=utf-8 # 证照模板下载,查询中心库,调用网站接口,下载文件保存到本地 import requests import json import datetime import xl ...

  9. Linux下修改MySQL可以远程访问

    所有操作均在MySQL命令行下执行,进入MySQL命令行:mysql -uroot -p #允许root账户远程登录 update mysql.user set host='%' where user ...

  10. SSD数据不能恢复?或许还有的救

    我们经常说机械硬盘相对于固态硬盘的一个优势是数据可以恢复,难道SSD固态硬盘的数据就不能恢复了吗? 这里先简单介绍一下SSD的工作方式,SSD中的数据是以电子的形式通过浮栅保存的,写入就是通过增加电压 ...