java.lang.NoClassDefFoundError when adding com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0 dependency

huangapple go评论71阅读模式
英文:

java.lang.NoClassDefFoundError when adding com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0 dependency

问题

在将com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0依赖添加到我的build.gradle文件时,我遇到了这个错误:

Caused by:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'management.metrics-org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: io/opentelemetry/javaagent/instrumentation/internal/classloader/BootDelegationInstrumentation$Holder
at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:628)
at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at app//org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at app//org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at app//org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at app//org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at app//org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at app//org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
at app//org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
at app//org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)
at app//org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
... 150 more
Caused by:
java.lang.NoClassDefFoundError: io/opentelemetry/javaagent/instrumentation/internal/classloader/BootDelegationInstrumentation$Holder
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1220)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at java.desktop/com.sun.beans.finder.ClassFinder.findClass(ClassFinder.java:67)
at java.desktop/com.sun.beans.finder.ClassFinder.findClass(ClassFinder.java:110)
at java.desktop/java.beans.Introspector.findCustomizerClass(Introspector.java:1125)
at java.desktop/java.beans.Introspector.getTargetBeanDescriptor(Introspector.java:1119)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:445)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:283)
at java.desktop/java.beans.Introspector.<init>(Introspector.java:427)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:283)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:225)
at org.springframework.beans.CachedIntrospectionResults.getBeanInfo(CachedIntrospectionResults.java:254)
at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:279)
at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:183)
at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:174)
at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptors(BeanWrapperImpl.java:248)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1594)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1434)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
... 160 more
Caused by:
java.lang.ClassNotFoundException: io.opentelemetry.javaagent.instrumentation.internal.classloader.BootDelegationInstrumentation$Holder
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1220)
... 180 more
Does anyone know what is the cause of it? I tried to upgrade the version but it requires different spring boot version that I am using. I am using opentelemetry in version 1.19.0. Could not find solution to this.
<details>
<summary>英文:</summary>
When adding com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0 dependency to my build.gradle file I am getting this error:
Caused by:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name &#39;management.metrics-org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties&#39;: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: io/opentelemetry/javaagent/instrumentation/internal/classloader/BootDelegationInstrumentation$Holder
at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:628)
at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
at app//org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
at app//org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
at app//org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
at app//org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
at app//org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276)
at app//org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391)
at app//org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311)
at app//org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887)
at app//org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791)
... 150 more
Caused by:
java.lang.NoClassDefFoundError: io/opentelemetry/javaagent/instrumentation/internal/classloader/BootDelegationInstrumentation$Holder
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1220)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at java.desktop/com.sun.beans.finder.ClassFinder.findClass(ClassFinder.java:67)
at java.desktop/com.sun.beans.finder.ClassFinder.findClass(ClassFinder.java:110)
at java.desktop/java.beans.Introspector.findCustomizerClass(Introspector.java:1125)
at java.desktop/java.beans.Introspector.getTargetBeanDescriptor(Introspector.java:1119)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:445)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:283)
at java.desktop/java.beans.Introspector.&lt;init&gt;(Introspector.java:427)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:283)
at java.desktop/java.beans.Introspector.getBeanInfo(Introspector.java:225)
at org.springframework.beans.CachedIntrospectionResults.getBeanInfo(CachedIntrospectionResults.java:254)
at org.springframework.beans.CachedIntrospectionResults.&lt;init&gt;(CachedIntrospectionResults.java:279)
at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:183)
at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:174)
at org.springframework.beans.BeanWrapperImpl.getPropertyDescriptors(BeanWrapperImpl.java:248)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1594)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1574)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1434)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619)
... 160 more
Caused by:
java.lang.ClassNotFoundException: io.opentelemetry.javaagent.instrumentation.internal.classloader.BootDelegationInstrumentation$Holder
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1220)
... 180 more
Does anyone know what is the cause of it? I tried to upgrade the version but it requires different spring boot version that I am using. I am using opentelemetry in version 1.19.0. Could not find solution to this.
</details>
# 答案1
**得分**: 1
这个错误通常发生在`spring-cloud-azure-starter-active-directory`依赖项与项目中的其他依赖项之间存在版本不兼容性时。
- 要解决这个问题,请检查项目中所有依赖项的版本兼容性。
- 包含与您的Spring Boot应用程序兼容的包版本。
- 要避免这个错误,您需要降级/升级项目中Spring Boot的版本。
- 正如[MSdoc](https://learn.microsoft.com/en-us/azure/developer/java/spring-framework/spring-boot-starter-for-azure-active-directory-developer-guide?tabs=SpringCloudAzure4x#prerequisites)中所提到的,您需要使用Spring Boot 2.5或更高版本。
我已经创建了一个简单的Spring Boot应用程序(版本3.1.0)并使用了依赖项`com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0`:
**build.gradle:**
```java
plugins {  
id 'java'  
id 'org.springframework.boot' version '3.1.0'  
id 'io.spring.dependency-management' version '1.1.0'  
}  
group = 'com.example'  
version = '0.0.1-SNAPSHOT'  
sourceCompatibility = '17'  
dependencies {  
implementation 'org.springframework.boot:spring-boot-starter-web'  
implementation 'com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0'  
developmentOnly 'org.springframework.boot:spring-boot-devtools'  
testImplementation 'org.springframework.boot:spring-boot-starter-test'  
}

我能够成功构建和运行这个应用程序。

java.lang.NoClassDefFoundError when adding com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0 dependency

响应:

java.lang.NoClassDefFoundError when adding com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0 dependency

java.lang.NoClassDefFoundError when adding com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0 dependency

英文:

This error usually occurs when there is version incompatibility between the spring-cloud-azure-starter-active-directory dependency and other dependencies in your project.

  • To resolve this, check the compatibility of the versions of all the dependencies in your project.
  • Include the package versions which are compatible to your spring-boot application.
  • To avoid this error, you have to downgrade/upgrade your spring-boot version of your project.
  • As mentioned in the MSdoc, you need spring boot 2.5 or above versions.

I have created a simple spring-boot application (version 3.1.0) and used the dependency com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0:

build.gradle:

plugins {  
id &#39;java&#39;  
id &#39;org.springframework.boot&#39; version &#39;3.1.0&#39;  
id &#39;io.spring.dependency-management&#39; version &#39;1.1.0&#39;  
}  
  
group = &#39;com.example&#39;  
version = &#39;0.0.1-SNAPSHOT&#39;  
sourceCompatibility = &#39;17&#39;  
  
dependencies {  
implementation &#39;org.springframework.boot:spring-boot-starter-web&#39;  
implementation &#39;com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0&#39;  
developmentOnly &#39;org.springframework.boot:spring-boot-devtools&#39;  
testImplementation &#39;org.springframework.boot:spring-boot-starter-test&#39;  
}

I am able to build and run the application successfully.

java.lang.NoClassDefFoundError when adding com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0 dependency

Response:

java.lang.NoClassDefFoundError when adding com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0 dependency

java.lang.NoClassDefFoundError when adding com.azure.spring:spring-cloud-azure-starter-active-directory:4.3.0 dependency

huangapple
  • 本文由 发表于 2023年6月5日 18:12:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76405399.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定