尝试连接到azure eventhub时出错:azuretokencredentials/illegalargumentexception:name

vyu0f0g1  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(382)

我正在学习如何在SpringBoot中设置到azure eventhub的连接的教程:[1]
启动spring boot应用程序时,出现以下错误:

2021-01-07 13:37:25.447  WARN 16444 --- [           main] ConfigServletWebServerApplicationContext :
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
'resourceManagerProvider' defined in class path resource
[com/microsoft/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.class]: Unsatisfied
dependency expressed through method 'resourceManagerProvider' parameter 0; nested exception is 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'azure'
defined in class path resource
[com/microsoft/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.class]: Unsatisfied
dependency expressed through method 'azure' parameter 0; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'credentials'
defined in class path resource
[com/microsoft/azure/spring/cloud/autoconfigure/context/AzureContextAutoConfiguration.class]: Bean
instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate
[com.microsoft.azure.credentials.AzureTokenCredentials]: Factory method 'credentials' threw exception;
nested exception is java.lang.IllegalArgumentException: name

my.azureauth看起来类似于[1]中的on。
我正在使用Java11。以下是我的pom的相关部分:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>spring-cloud-azure-eventhubs-stream-binder</artifactId>
            <version>1.2.7</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>azure-servicebus-jms-spring-boot-starter</artifactId>
            <version>2.3.5</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- Workaround. -->
        <!-- Apparently com.microsoft.azure:spring-cloud-azure-eventhubs-stream-binder:1.2.7 has a transitive -->
        <!-- dependency to the following package. However, it seems that the version is not pinned correctly, so -->
        <!-- we have to pin the version to a compatible one as a workaround. -->
        <!-- 7.5 is apparently the latest version in which com.nimbusds.oauth2.sdk.http.CommonContentTypes is available. -->
        <!-- For a similar (but different) issue see also https://github.com/microsoft/azure-spring-boot/issues/650 -->
        <dependency>
            <groupId>com.nimbusds</groupId>
            <artifactId>oauth2-oidc-sdk</artifactId>
            <version>7.5</version>
        </dependency>

请注意有关依赖关系的解决方法 com.nimbusds .
我试着导航到相关的代码。然而,由于某种原因 AzureContextAutoConfiguration.credentials 在ide的反汇编代码中不可用。
是我在工作区中使用的版本 pom.xml 合适吗?有没有人知道这个错误是什么意思以及如何修复它?有谁能报告,这个教程仍然有效吗?
[1] https://docs.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-cloud-stream-binder-java-app-azure-event-hub

lc8prwob

lc8prwob1#

所以根本问题是
“未能示例化[com.microsoft.azure.credentials.azuretokencredentials]:工厂方法'credentials'引发异常;嵌套异常为java.lang.illegalargumentexception:name“
我建议你核实一下 my.azureauth 以及 application.properties 又一次违反了指南。
另外,正如指南所建议的,如果您使用的是jdkversion9或更高版本(这里使用的是11),请添加以下依赖项

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.1</version>
    <scope>runtime</scope>
</dependency>

相关问题