【问题标题】:Error when trying to connect to Azure Eventhub: AzureTokenCredentials / IllegalArgumentException: name尝试连接到 Azure Eventhub 时出错:AzureTokenCredentials / IllegalArgumentException: name
【发布时间】:2021-04-13 05:34:45
【问题描述】:

我正在关注有关如何在 Spring Boot 中设置与 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。

我正在使用 Java 11。这是我的 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

【问题讨论】:

  • 对于任何可能遇到类似问题的人:我遇到了许多依赖冲突的问题,我最终通过不在同一个应用程序中同时使用 eventthub 和 servicebus 依赖来解决这些问题。我尝试了一段时间来解决这些问题,但在这种分裂对我来说很容易之后,我没有进一步追求这条道路。

标签: java azure spring-boot azure-eventhub azure-authentication


【解决方案1】:

所以这里的根本问题是

"实例化失败 [com.microsoft.azure.credentials.AzureTokenCredentials]:工厂方法“凭据”抛出异常; 嵌套异常是 java.lang.IllegalArgumentException: name"

我建议您根据guide 再次验证您的my.azureauthapplication.properties 文件。

另外,正如guide 所建议的,如果您使用的是 JDK 版本 9 或更高版本(这里使用的是 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-24
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 2019-05-25
    相关资源
    最近更新 更多