這個問題之前出現過一次,和同事討論了2天,解決了。后來合 了一下master的分支,問題又出現了,但是忘記了解決方法。現在記錄一下免得時間長了又忘記了。
問題描述:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'buyerSubjectCollector': Unsatisfied dependency expressed through field 'subjectValueCollects'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'subjectValueCollects' defined in class path resource [bbq-common.xml]: Cannot resolve reference to bean 'identifyBuyerSubjectQuery' while setting bean property 'objectSubjectQueryList' with key [0]; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'identifyBuyerSubjectQuery': Unsatisfied dependency expressed through field 'uicReadServiceClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicReadServiceClient' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Cannot resolve reference to bean 'uicExtraReadServiceClient' while setting bean property 'uicExtraReadServiceClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicExtraReadServiceClient' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Cannot resolve reference to bean 'uicCacheService' while setting bean property 'uicCacheService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicCacheService' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: UICCacheService-initTair error , unit:null forceNodeGroup: null at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:364) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1268) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:756) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:123) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:666) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:353) at org.springframework.boot.SpringApplication.run(SpringApplication.java:300) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1082) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1071) at com.wdk.commercial.Application.main(Application.java:32) ... 6 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'subjectValueCollects' defined in class path resource [bbq-common.xml]: Cannot resolve reference to bean 'identifyBuyerSubjectQuery' while setting bean property 'objectSubjectQueryList' with key [0]; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'identifyBuyerSubjectQuery': Unsatisfied dependency expressed through field 'uicReadServiceClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicReadServiceClient' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Cannot resolve reference to bean 'uicExtraReadServiceClient' while setting bean property 'uicExtraReadServiceClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicExtraReadServiceClient' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Cannot resolve reference to bean 'uicCacheService' while setting bean property 'uicCacheService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicCacheService' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: UICCacheService-initTair error , unit:null forceNodeGroup: null at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:382) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:157) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1533) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1280) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:211) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1131) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1059) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:583) ... 25 more Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'identifyBuyerSubjectQuery': Unsatisfied dependency expressed through field 'uicReadServiceClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicReadServiceClient' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Cannot resolve reference to bean 'uicExtraReadServiceClient' while setting bean property 'uicExtraReadServiceClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicExtraReadServiceClient' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Cannot resolve reference to bean 'uicCacheService' while setting bean property 'uicCacheService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicCacheService' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: UICCacheService-initTair error , unit:null forceNodeGroup: null at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:364) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1268) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ... 40 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicReadServiceClient' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Cannot resolve reference to bean 'uicExtraReadServiceClient' while setting bean property 'uicExtraReadServiceClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicExtraReadServiceClient' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Cannot resolve reference to bean 'uicCacheService' while setting bean property 'uicCacheService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicCacheService' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: UICCacheService-initTair error , unit:null forceNodeGroup: null at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1533) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1280) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:211) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1131) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1059) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:583) ... 50 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicExtraReadServiceClient' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Cannot resolve reference to bean 'uicCacheService' while setting bean property 'uicCacheService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicCacheService' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: UICCacheService-initTair error , unit:null forceNodeGroup: null at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1533) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1280) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:551) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ... 63 more Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'uicCacheService' defined in file [/Users/bitidawang/Downloads/software/workspace/wdk-commercial/wdk-commercial-core-start/target/classes/spring/spring-wdk-commercial-uic.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: UICCacheService-initTair error , unit:null forceNodeGroup: null at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1630) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:481) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351) ... 73 more Stopping available components Caused by: java.lang.RuntimeException: UICCacheService-initTair error , unit:null forceNodeGroup: null at com.taobao.uic.common.cache.TairCacheFactory.initTair(TairCacheFactory.java:68) at com.taobao.uic.common.cache.TairCacheFactory.getInstance(TairCacheFactory.java:42) at com.taobao.uic.common.cache.DefaultUICCacheService.initTair(DefaultUICCacheService.java:214) at com.taobao.uic.common.cache.DefaultUICCacheService.init(DefaultUICCacheService.java:163) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1759) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1696) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1626) ... 80 more Caused by: java.lang.RuntimeException: init uicCacheManager failed isNewVersion :true at com.taobao.uic.common.cache.uictair.MultiClusterTairProxyImpl.init(MultiClusterTairProxyImpl.java:107) at com.taobao.uic.common.cache.TairCacheFactory.initTair(TairCacheFactory.java:61) ... 90 more Caused by: java.lang.RuntimeException: com.taobao.tair.impl.mc.ShieldTairManager was loaded by com.taobao.pandora.boot.loader.ReLaunchURLClassLoader@6da9dc6, it should be loaded by Pandora Container. Can not load this fake sdk class. please refer to xxxx(這里是文檔地址,公司保密協議不好透露) for the solution. at com.taobao.tair.impl.mc.ShieldTairManager.<init>(ShieldTairManager.java) at com.taobao.uic.common.cache.tair.ShieldTairCacheManager.init(ShieldTairCacheManager.java:32) at com.taobao.uic.common.cache.uictair.MultiClusterTairProxyImpl.init(MultiClusterTairProxyImpl.java:103) ... 91 more
解決辦法先放在前面:
快捷鍵搜索com.taobao.tair.impl.mc.ShieldTairManager,仔細看,出現在兩個包里,按照自己的業務,在所有子模塊中根據maven help插件搜索,排除掉其中一個。
解決路程:
看到報錯一大堆,前面的基本都不用管,看最后報錯比較簡短的那一句。
com.taobao.tair.impl.mc.ShieldTairManager was loaded by com.taobao.pandora.boot.loader.ReLaunchURLClassLoader@6da9dc6, it should be loaded by Pandora Container. Can not load this fake sdk class. please refer to xxxx(這里是文檔地址,公司保密協議不好透露) for the solution
意思是說ShieldTairManager 這個類是Pandora Container容器加載的,請參考某某文檔解決,
復制下來文檔鏈接在瀏覽器打開,發現沒有權限,阿里的權限控制是做的比較嚴格的,到處都限制,好吧,那就不看文檔了。
按照需要Pandora Container容器加載的思路,腦海里出現各種假設,難道這個類被別的人修改過了?難道本地啟動不起來了嗎?難道我本地啟動的不是Pandora Container容器嗎?
思路錯了就會把你帶到無盡的深淵當中。
無意當中拷貝了com.taobao.tair.impl.mc.ShieldTairManager,快捷鍵在項目中搜索,發現這個類出現在兩個jar包中,
按照之前本地debug段點調試,發現一個奇怪的現象,
什么?構造器中構造一個對象時你直接給我拋出一個異常??拋出的異常和項目啟動時候拋出的異常是一樣的,com.taobao.tair.impl.mc.ShieldTairManager was loaded by..........
看看ShieldTairManager出現在哪個jar包中,發現出現在一個A包中和一個B包中,B包是自己的外部依賴C引進來的,是需要的,那就把A包從項目中排除吧,
好吧,搜索各個子模塊,去掉A包,項目本地啟動,完美解決。
小經驗總結:
1.看異常看最后一個報錯,最后一個一般才是錯誤的主要原因。注意是一般。
2.思路錯了會帶你到無盡的深淵,一條路走不通試試另一條路。
3.一個類出現在兩個jar包中,會出現奇怪的問題,必須排除掉其中一個或者改變依賴順序。
4.要堅韌,要有耐心。