记录一次解决org.springframework.beans.factory.BeanCurrentlyInCreationException的经过

起因:新需求本地测试(web容器是jetty)通过后,通过自动化构建部署工具部署到测试环境(web容器是weblogic)测试。启动应用服务时,提示16274 [2020-05-08 18:10:44 ] - [[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'] -   [ip=,  ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'payNoService': Bean with name 'payNoService' has been injected into other beans [onlineSaleServerOnline] in its raw version as part of a circular reference, but has eventually been wrapped. This means that said other beans do not use the final version of the bean. This is often the result of over-eager type matching - consider using 'getBeanNamesOfType' with the 'allowEagerInit' flag turned off, for example.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:548) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628) ~[spring-beans-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932) ~[spring-context-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479) ~[spring-context-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389) ~[spring-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294) ~[spring-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) [spring-web-3.2.4.RELEASE.jar:3.2.4.RELEASE]
    at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:481) [weblogic.jar:10.3.6.0]
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) [com.bea.core.weblogic.security.identity_1.2.0.0.jar:1.2.0.0]
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) [com.bea.core.weblogic.security.wls_1.0.0.0_6-2-0-0.jar:6.2.0.0]
    at weblogic.servlet.internal.EventsManager.notifyContextCreatedEvent(EventsManager.java:181) [weblogic.jar:10.3.6.0]
    at weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1871) [BUG26519424_10360171017.jar:10.3.6.0]
    at weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:3173) [BUG26519424_10360171017.jar:10.3.6.0]
    at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1529) [BUG26519424_10360171017.jar:10.3.6.0]
    at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:488) [BUG26519424_10360171017.jar:10.3.6.0]
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425) [weblogic.jar:10.3.6.0]
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52) [weblogic.jar:10.3.6.0]
    at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119) [weblogic.jar:10.3.6.0]
    at weblogic.application.internal.flow.ScopedModuleDriver.start(ScopedModuleDriver.java:200) [weblogic.jar:10.3.6.0]
    at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:247) [weblogic.jar:10.3.6.0]
    at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425) [weblogic.jar:10.3.6.0]
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52) [weblogic.jar:10.3.6.0]
    at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119) [weblogic.jar:10.3.6.0]
    at weblogic.application.internal.flow.StartModulesFlow.activate(StartModulesFlow.java:27) [weblogic.jar:10.3.6.0]
    at weblogic.application.internal.BaseDeployment$2.next(BaseDeployment.java:671) [weblogic.jar:10.3.6.0]
    at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52) [weblogic.jar:10.3.6.0]
    at weblogic.application.internal.BaseDeployment.activate(BaseDeployment.java:212) [weblogic.jar:10.3.6.0]
    at weblogic.application.internal.SingleModuleDeployment.activate(SingleModuleDeployment.java:44) [weblogic.jar:10.3.6.0]
    at weblogic.application.internal.DeploymentStateChecker.activate(DeploymentStateChecker.java:161) [weblogic.jar:10.3.6.0]
    at weblogic.deploy.internal.targetserver.AppContainerInvoker.activate(AppContainerInvoker.java:80) [BUG26519424_10360171017.jar:10.3.6.0]
    at weblogic.deploy.internal.targetserver.BasicDeployment.activate(BasicDeployment.java:187) [BUG26519424_10360171017.jar:10.3.6.0]
    at weblogic.deploy.internal.targetserver.BasicDeployment.activateFromServerLifecycle(BasicDeployment.java:379) [BUG26519424_10360171017.jar:10.3.6.0]
    at weblogic.management.deploy.internal.DeploymentAdapter$1.doActivate(DeploymentAdapter.java:51) [weblogic.jar:10.3.6.0]
    at weblogic.management.deploy.internal.DeploymentAdapter.activate(DeploymentAdapter.java:200) [weblogic.jar:10.3.6.0]
    at weblogic.management.deploy.internal.AppTransition$2.transitionApp(AppTransition.java:30) [weblogic.jar:10.3.6.0]
    at weblogic.management.deploy.internal.ConfiguredDeployments.transitionApps(ConfiguredDeployments.java:240) [weblogic.jar:10.3.6.0]
    at weblogic.management.deploy.internal.ConfiguredDeployments.activate(ConfiguredDeployments.java:169) [weblogic.jar:10.3.6.0]
    at weblogic.management.deploy.internal.ConfiguredDeployments.deploy(ConfiguredDeployments.java:123) [weblogic.jar:10.3.6.0]
    at weblogic.management.deploy.internal.DeploymentServerService.resume(DeploymentServerService.java:180) [weblogic.jar:10.3.6.0]
    at weblogic.management.deploy.internal.DeploymentServerService.start(DeploymentServerService.java:96) [weblogic.jar:10.3.6.0]
    at weblogic.t3.srvr.SubsystemRequest.run(SubsystemRequest.java:64) [weblogic.jar:10.3.6.0]
    at weblogic.work.ExecuteThread.execute(ExecuteThread.java:263) [BUG26519424_10360171017.jar:1.11.0.0]
    at weblogic.work.ExecuteThread.run(ExecuteThread.java:221) [BUG26519424_10360171017.jar:1.11.0.0]

问题原因:Spring循环依赖

  • payNoService依赖paymentSupport,paymentSupport依赖onlineSaleServerOnline

  • onlineSaleServerOnline依赖payNoService

解决办法:删掉paymentSupport(多余的实现),使paymentSupport不依赖onlineSaleServerOnline,这样就不存在payNoService和onlineSaleServerOnline循环依赖了。

验证:代码提交后重新构建部署,应用启动成功,耶!

感想:开发中应避免循环依赖以减少不必要的问题。

           所见即所得,有问题要先解决问题,不要想着代码没变化就没问题,不然会错过解决问题的黄金时间。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值