1

我正在将我的 Spring 项目从 4.3.23 版升级到 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>

但是在运行我得到的代码时java.lang.NoClassDefFoundError: org/springframework/core/JdkVersion

经过搜索,我发现 JdkVersion 在 Spring 5.x 中被删除

我想知道如何修复我的代码以在 Spring 5.x 中正常工作。

这是错误的完整堆栈跟踪:

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

提前致谢!

4

3 回答 3

1

我假设您没有使用 Spring Boot,而我们正在谈论“普通弹簧”应用程序。

显然,spring 框架中尝试使用缺少的类的代码属于 spring 4 生态系统(否则任何依赖于 Spring 5 并使用 ldap 集成的应用程序都会失败,并且 spring 团队会有一个重大错误)

假设没有重大错误,您的应用程序的类路径中必须有一些 spring 4 jar

所以我建议执行以下操作:

  1. 检查类路径。因为我假设,你正在编译一个 WAR - 用 WinRar 或其他东西打开工件并查看WEB-INF/lib文件夹的内容。如果您看到属于 spring 4 的内容 - 请pom.xml使用正确的依赖项修复您的内容。如果你编译 EAR - 它可能有很多模块需要检查,但基本上过程是相同的,我相信你明白了

  2. Weblogic 可能在某个共享文件夹中有一些“共享”的 jars(包括 spring)。我对这个应用服务器不是很熟悉,但很有可能这些 jar 属于 spring 4 生态系统,它们可能会在运行时“找到自己的方式”进入应用程序的类路径。Maven 显然不会表明这一点。

于 2021-03-13T06:27:10.753 回答
0

您应该一起更新所有 spring 依赖项(在本例中为 spring ldap),检查是否所有 spring 依赖项都更新到 spring 5,因为 spring 是一个非常模块化的框架,定义一个关于其模块的版本管理的变量总是有帮助的

于 2021-03-13T00:27:57.980 回答
0

spring-ldap.jar 在 Spring 4 中用于与 LDAP 交互,但这个 jar 与 Spring 5 不兼容并导致 NoClassDefFoundError: org/springframework/core/JdkVersion

由于 JdkVersion 类在 Spring 5 中从 spring-core jar 中删除

如果您在 Spring 5 中需要 Spring for LDAP,请使用 spring-ldap-core 依赖项

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

还要检查是否还有其他较旧的弹簧罐。

于 2021-05-30T13:25:42.820 回答