Spring无法自动连接Azure存储Blob

Spring无法自动连接Azure存储Blob,spring,azure,spring-batch,azure-storage,azure-storage-blobs,Spring,Azure,Spring Batch,Azure Storage,Azure Storage Blobs,我有一个Spring批处理,它有一个Azure存储Blob的写入程序 我正在使用此Azure/Spring依赖项: azure spring boot starter存储3.4.0 在我的应用程序属性上,我有: azure.storage.accountName=myAccount azure.storage.accountKey=myKey 然后在我的BatchConfig类中,我自动连接了AZ存储: @Autowired private BlobServiceClientBuilder b

我有一个Spring批处理,它有一个Azure存储Blob的写入程序

我正在使用此Azure/Spring依赖项:

azure spring boot starter存储3.4.0

在我的应用程序属性上,我有:

azure.storage.accountName=myAccount
azure.storage.accountKey=myKey
然后在我的BatchConfig类中,我自动连接了AZ存储:

@Autowired
private BlobServiceClientBuilder blobServiceClientBuilder;

private final BlobServiceAsyncClient blobServiceAsyncClient = blobServiceClientBuilder.buildAsyncClient();
现在,当我启动应用程序时,我得到一个NullPointerException,因为BlobServiceClientBuilder无法实例化

Caused by: java.lang.NullPointerException: null
at com.example.dbreader.configuration.BatchConfig.<init>(BatchConfig.java:55) ~[classes/:na]
at com.example.dbreader.configuration.BatchConfig$$EnhancerBySpringCGLIB$$58787751.<init>(<generated>) ~[classes/:na]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_221]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_221]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_221]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_221]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:212) ~[spring-beans-5.3.5.jar:5.3.5]

我遇到了同样的问题。最后我发现buildClient()方法无法放入全局或构造函数中。只要把它放在GET/POST方法中,它就会工作。FYR

   @Autowired
private BlobServiceClientBuilder blobServiceClientBuilder;

private BlobServiceClient blobServiceClient;



@GetMapping
public String readBlobFile() throws IOException {
    blobServiceClient = blobServiceClientBuilder.buildClient();
    AzureStorageResourcePatternResolver storageResourcePatternResolver = new AzureStorageResourcePatternResolver(blobServiceClient);

您可能必须创建bean并将其交给框架,而不是创建实例并将其保存,而且BatchConfig#55中似乎存在错误。您需要首先确保正确配置Azure存储资源:这里是指向官方文档的链接:。请删除“+”#{stepExecutionContext['marketName']}”,看看这是否解决了问题。我怀疑
marketName
键在
stepExecutionContext
中是空的。请共享您的
BatchConfig
类的代码,以便能够以有效的方式帮助您。
   @Autowired
private BlobServiceClientBuilder blobServiceClientBuilder;

private BlobServiceClient blobServiceClient;



@GetMapping
public String readBlobFile() throws IOException {
    blobServiceClient = blobServiceClientBuilder.buildClient();
    AzureStorageResourcePatternResolver storageResourcePatternResolver = new AzureStorageResourcePatternResolver(blobServiceClient);