简体   繁体   English

从 Spring 4 升级到 Spring 5 - NoClassDefFoundError: org/springframework/core/JdkVersion

[英]Upgrading from Spring 4 to Spring 5 - NoClassDefFoundError: org/springframework/core/JdkVersion

I am upgrading my Spring project from version 4.3.23 to version 5.2.13我正在将我的 Spring 项目从版本 4.3.23 升级到版本 5.2.13

I have the following code in my ldap.xml file in the project which was working fine in 4.3.23 but erroring out in 5.2.13:我在项目的 ldap.xml 文件中有以下代码,在 4.3.23 中运行良好,但在 5.2.13 中出错:

<bean id="contextSourceReadTarget" class="org.springframework.ldap.core.support.LdapContextSource">
        <property name="urls" value="ldap://localhost:12345" />
        <property name="base" value="dc=memorynotfound,dc=com" />
        <property name="userDn" value="uid=admin" />
        <property name="password" value="secret" />
        <property name="dirObjectFactory"
            value="org.springframework.ldap.core.support.DefaultDirObjectFactory" />
        <property name="pooled" value="false" />
        <property name="referral" value="follow" />
</bean>

But when running the code I am getting java.lang.NoClassDefFoundError: org/springframework/core/JdkVersion但是在运行代码时,我得到java.lang.NoClassDefFoundError: org/springframework/core/JdkVersion

After searching I found that JdkVersion is removed in Spring 5.x经过搜索,我发现在 Spring 5.x 中删除了 JdkVersion

I would like to know how I can fix my code to work fine with Spring 5.x.我想知道如何修复我的代码以在 Spring 5.x 上正常工作。

Here is the complete stacktrace of the error:这是错误的完整堆栈跟踪:

java.lang.NoClassDefFoundError: org/springframework/core/JdkVersion
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1799)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:401)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:292)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
        at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:719)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:344)
        at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)
        at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
        at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
        at weblogic.servlet.internal.EventsManager.executeContextListener(EventsManager.java:251)
        at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:204)
        at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:189)
        at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1929)
        at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3191)
        at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1864)
        at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:919)
        at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:360)
        at weblogic.application.internal.ExtensibleModuleWrapper$StartStateChange.next(ExtensibleModuleWrapper.java:356)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
        at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:138)
        at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:233)
        at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:228)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
        at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:78)
        at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:52)
        at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:752)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
        at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:262)
        at weblogic.application.internal.EarDeployment.activate(EarDeployment.java:66)
        at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:165)
        at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:90)
        at weblogic.deploy.internal.targetserver.BasicDeployment.activate(BasicDeployment.java:274)
        at weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.java:507)
        at weblogic.management.deploy.internal.DeploymentAdapter$1.doActivate(DeploymentAdapter.java:53)
        at weblogic.management.deploy.internal.DeploymentAdapter.activate(DeploymentAdapter.java:202)
        at weblogic.management.deploy.internal.AppTransition$2.transitionAppInternal(AppTransition.java:53)
        at weblogic.management.deploy.internal.AppTransition.transitionApp(AppTransition.java:138)
        at weblogic.management.deploy.internal.ConfiguredDeployments$2.doItem(ConfiguredDeployments.java:741)
        at weblogic.management.deploy.internal.parallel.BucketInvoker$2.run(BucketInvoker.java:95)
        at weblogic.work.ContextWrap.run(ContextWrap.java:46)
        at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:681)
        at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:352)
        at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:337)
        at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:57)
        at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
        at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:655)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:420)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:360)
Caused by: java.lang.NoClassDefFoundError: org/springframework/core/JdkVersion
        at org.springframework.ldap.core.support.AbstractContextSource.getJdkVersion(AbstractContextSource.java:485)
        at org.springframework.ldap.core.support.AbstractContextSource.afterPropertiesSet(AbstractContextSource.java:342)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1858)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1795)
        ... 57 more

Thanks in advance!提前致谢!

I assume you're not using Spring boot and we're talking about the “plain spring” application.我假设您没有使用 Spring 引导,我们正在谈论“普通弹簧”应用程序。

Obviously the code within spring framework that tries to use the missing class belongs to spring 4 ecosystem (otherwise any application that depends on Spring 5 and uses ldap integration would have failed and spring team would have had a major bug on that) Obviously the code within spring framework that tries to use the missing class belongs to spring 4 ecosystem (otherwise any application that depends on Spring 5 and uses ldap integration would have failed and spring team would have had a major bug on that)

Assuming there is no major bug on that, there must be some spring 4 jar in the class path of your application假设没有重大错误,则应用程序的 class 路径中必须有一些 spring 4 jar

So I suggest doing the following:所以我建议执行以下操作:

  1. Check the class path.检查 class 路径。 Since I assume, you're compiling a WAR - open up the artifact with WinRar or something and see the content of WEB-INF/lib folder.因为我假设,你正在编译一个 WAR - 用 WinRar 或其他东西打开工件并查看WEB-INF/lib文件夹的内容。 If you see something that belongs to spring 4 - fix your pom.xml with correct dependencies.如果你看到属于 spring 4 的东西 - 用正确的依赖关系修复你的pom.xml If you compile EAR - it might have many modules that should be checked but basically the procedure is the same, I'm sure you've got the point如果你编译 EAR - 它可能有很多模块需要检查,但基本上过程是相同的,我相信你明白了

  2. Weblogic might have some “shared” jars (including spring) in some shared folder. Weblogic 可能在某个共享文件夹中有一些“共享”的 jars(包括 spring)。 I'm not really familiar with this application server, but the chances are that these jars belong to spring 4 ecosystem and they might “find their way” to the class path of your application in runtime.我对这个应用服务器不是很熟悉,但很有可能这些 jars 属于 spring 4 生态系统,它们可能会“找到自己的方式”到应用程序运行时路径中的 class 路径。 Maven won't obviously show that. Maven 不会明显表明这一点。

you should update all your spring dependencies together (in this case, spring ldap), check if all your spring dependencies are updated to spring 5, because spring is a very modular framework, it's always helpful to define a variable regarding version management of it's modules you should update all your spring dependencies together (in this case, spring ldap), check if all your spring dependencies are updated to spring 5, because spring is a very modular framework, it's always helpful to define a variable regarding version management of it's modules

spring-ldap.jar was used to interact with LDAP in Spring 4 but this jar is not compatible with Spring 5 and leads to NoClassDefFoundError: org/springframework/core/JdkVersion spring-ldap.jar was used to interact with LDAP in Spring 4 but this jar is not compatible with Spring 5 and leads to NoClassDefFoundError: org/springframework/core/JdkVersion

As JdkVersion class is removed from spring-core jar in Spring 5由于 JdkVersion class 从 Spring 5 中的弹簧芯 jar 中删除

If you require Spring for LDAP in Spring 5 use spring-ldap-core dependency如果您需要 Spring 用于 Spring 5 中的 LDAP 5 使用 spring-ldap-core 依赖项

<dependency>
   <groupId>org.springframework.ldap</groupId>
   <artifactId>spring-ldap-core</artifactId>
   <version>2.3.4.RELEASE</version>
</dependency>

Also check if there are any other older spring jars.还要检查是否还有其他较旧的 spring jars。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.NoClassDefFoundError: org/springframework/core/JdkVersion - java.lang.NoClassDefFoundError: org/springframework/core/JdkVersion 从Spring 4.3升级到5.0后,Spring Security OAuth中的“NoClassDefFoundError:org / springframework / web / method / HandlerMethodSelector” - “NoClassDefFoundError: org/springframework/web/method/HandlerMethodSelector” in Spring Security OAuth after upgrading from Spring 4.3 to 5.0 java.lang.NoClassDefFoundError:升级到Spring 5时org / springframework / transaction / interceptor / TransactionAttributeSource错误 - java.lang.NoClassDefFoundError: org/springframework/transaction/interceptor/TransactionAttributeSource error while upgrading to spring 5 org / springframework / transaction / support / TransactionSynchronization上的Spring NoClassDefFoundError - Spring NoClassDefFoundError on org/springframework/transaction/support/TransactionSynchronization NoSuchMethodError: org.springframework.data.redis.core.RedisTemplate.delete(Ljava/lang/Object;)V 同时将 Spring boot 从 1.5.3 升级到 2.1.6 - NoSuchMethodError: org.springframework.data.redis.core.RedisTemplate.delete(Ljava/lang/Object;)V while upgrading Spring boot from 1.5.3 to 2.1.6 Spring 5.1 + Tomcat 9 + Java 10 +模块化项目= java.lang.NoClassDefFoundError:org / springframework / core / io / Resource - Spring 5.1 + Tomcat 9 + Java 10 + moduled project = java.lang.NoClassDefFoundError: org/springframework/core/io/Resource JBoss Spring JMS异常:java.lang.NoClassDefFoundError:org / springframework / jms / core / MessageCreator - JBoss Spring JMS Exception : java.lang.NoClassDefFoundError: org/springframework/jms/core/MessageCreator Spring AOP错误:java.lang.NoClassDefFoundError:org / springframework / cglib / core / SpringNamingPolicy - Spring AOP Error : java.lang.NoClassDefFoundError: org/springframework/cglib/core/SpringNamingPolicy 春季错误:java.lang.NoClassDefFoundError:org / springframework / security / core / userdetails / memory / UserMap - Spring error: java.lang.NoClassDefFoundError: org/springframework/security/core/userdetails/memory/UserMap java.lang.NoClassDefFoundError:org / hibernate / cache / spi / RegionFactory - 从spring 3升级到spring 4 - java.lang.NoClassDefFoundError: org/hibernate/cache/spi/RegionFactory - When upgrading from spring 3 to spring 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM