英文:
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 '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>
# 答案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'
}
我能够成功构建和运行这个应用程序。
响应:
英文:
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 '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'
}
I am able to build and run the application successfully.
Response:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论