Azure-sdk-for-java: [BUG] azure-spring-boot-starter-keyvault-secrets 3.3.0 does not work.

Created on 26 Mar 2021  路  7Comments  路  Source: Azure/azure-sdk-for-java

Describe the bug

If you use azure-spring-boot-starter-keyvault-secrets:3.3.0 , you will got NoSuchMethodError exception. 3.2.0 works correctly.

Exception or Stack Trace

17:18:44.264 [main] DEBUG org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - Application failed to start due to an exception
java.lang.NoSuchMethodError: 'com.fasterxml.jackson.databind.cfg.MutableCoercionConfig com.fasterxml.jackson.databind.ObjectMapper.coercionConfigDefaults()'
        at com.azure.core.util.serializer.JacksonAdapter.<init>(JacksonAdapter.java:106)
        at com.azure.core.util.serializer.JacksonAdapter.createDefaultSerializerAdapter(JacksonAdapter.java:139)
        at com.azure.identity.implementation.IdentityClient.<clinit>(IdentityClient.java:94)
        at com.azure.identity.implementation.IdentityClientBuilder.build(IdentityClientBuilder.java:113)
        at com.azure.identity.ClientSecretCredential.<init>(ClientSecretCredential.java:50)
        at com.azure.identity.ClientSecretCredentialBuilder.build(ClientSecretCredentialBuilder.java:62)
        at com.azure.spring.keyvault.KeyVaultEnvironmentPostProcessorHelper.getCredentials(KeyVaultEnvironmentPostProcessorHelper.java:155)
        at com.azure.spring.keyvault.KeyVaultEnvironmentPostProcessorHelper.addKeyVaultPropertySource(KeyVaultEnvironmentPostProcessorHelper.java:88)
        at com.azure.spring.keyvault.KeyVaultEnvironmentPostProcessor.postProcessEnvironment(KeyVaultEnvironmentPostProcessor.java:47)
        at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:100)
        at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:86)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
        at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
        at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
        at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
        at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
        at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
        at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:362)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1313)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1302)
        at com.example.moris.springdemo.Application.main(Application.java:20)
17:18:44.268 [main] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter -

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    com.azure.core.util.serializer.JacksonAdapter.<init>(JacksonAdapter.java:106)

The following method did not exist:

    'com.fasterxml.jackson.databind.cfg.MutableCoercionConfig com.fasterxml.jackson.databind.ObjectMapper.coercionConfigDefaults()'

The method's class, com.fasterxml.jackson.databind.ObjectMapper, is available from the following locations:

    jar:file:/C:/Users/moris/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.11.4/jackson-databind-2.11.4.jar!/com/fasterxml/jackson/databind/ObjectMapper.class

The class hierarchy was loaded from the following locations:

    com.fasterxml.jackson.databind.ObjectMapper: file:/C:/Users/moris/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.11.4/jackson-databind-2.11.4.jar
    com.fasterxml.jackson.core.ObjectCodec: file:/C:/Users/moris/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.11.4/jackson-core-2.11.4.jar
    com.fasterxml.jackson.core.TreeCodec: file:/C:/Users/moris/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.11.4/jackson-core-2.11.4.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of com.fasterxml.jackson.databind.ObjectMapper

To Reproduce
I used the following tutorial as a reference and tried the latest version.

https://docs.microsoft.com/en-us/azure/developer/java/spring-framework/configure-spring-boot-starter-java-app-with-azure-key-vault

Setup (please complete the following information):

  • OS: WSL2(Windows10)
  • IDE : Maven
  • Java : openjdk 11.0.7 2020-04-14
  • spring-boot-starter:2.4.4

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • [X] Bug Description Added
  • [X] Repro Steps Added
  • [X] Setup information Added
Client azure-spring azure-spring-keyvault bug customer-reported

Most helpful comment

This appears to be related to https://github.com/Azure/azure-sdk-for-java/issues/19897.

The bug in the related issue was that the latest Azure SDKs are using Jackson 2.12 and was using Jackson 2.12 APIs and Spring Framework 2.4 uses Jackson 2.11. If Jackson 2.11 was resolved in the classpath the APIs being used by the Azure SDKs wouldn't exist. A hotfix of azure-core, where the APIs were being used, was released to remedy this, pulling in azure-core 1.14.1 should resolve the class not found exception.

All 7 comments

@stliu @vcolin7 can you please take a look

This appears to be related to https://github.com/Azure/azure-sdk-for-java/issues/19897.

The bug in the related issue was that the latest Azure SDKs are using Jackson 2.12 and was using Jackson 2.12 APIs and Spring Framework 2.4 uses Jackson 2.11. If Jackson 2.11 was resolved in the classpath the APIs being used by the Azure SDKs wouldn't exist. A hotfix of azure-core, where the APIs were being used, was released to remedy this, pulling in azure-core 1.14.1 should resolve the class not found exception.

yeah, it seems we missed this one @saragluna

@m-moris, please include this dependency management section into your project. The azure-spring-boot-bom will mange the version of azure-core.

<properties>
    <azure.version>3.3.0</azure.version>
  </properties>

<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>com.azure.spring</groupId>
        <artifactId>azure-spring-boot-bom</artifactId>
        <version>${azure.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

@saragluna

Thanks for the solution. My sample program just worked.
Should I always add dependency management section when using Azure Spring Boot Starter?

Thanks.

Yes, I think you could always add the dependency management section, whenever we perform a release for Spring Boot starters, we will release a bom for them at the same time. It will include the versions of starters will could run together as well as the sdk versions used in our Spring Boot starters.

Closing this issue now.

Was this page helpful?
0 / 5 - 0 ratings