Spring+SpringMVC+Mybatis dubbo整合 bean实例化失败

1、问题描述:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException: Error cd = q s J / [ Wreating bean with name 'com.taotao.service.ItemService': Instantiatim l : f L Pon of bean failed; nested exceptf X G !ion is java.lang.ExceptionInInitializerError

2、代码片段:

package c|  y c b O zom.taotao.se. . P Grvice;
import com.taot% Z t : d 0 o 7ao.pojo.TbItem;
public interface ItemService {
TbItem getItemById(long id);
}
package com.taotao.ser_ K zvice.impl;
import org.springfro 5 { [ e ? pamework.beans.factory.annotation.AutowirZ @ 4 = { V zed;
import og ( x D u w . 2rg.sT ` W c # C r Springframework.stereotype.Se# 1 [ 1 | D ~ 5rvice;
import com.taotao.mapper.TbItemMapper;
import com.taotao.pojo.TbItem;
iy h ^ ] . ^ b # 7mport com.taotao.service.Ites g ) D ? l @ @ ;mService;
//@Service("itemService")
@Service("ItemService")
public class ItemServiceImpl implements ItemService {
@Autowired
priP I e H 6vate TbItemMapper itemMapper;
@Override
public TbItem getItemById(long id) {
// TODO Auto-generated method stub
TbItem item = itemMapper.selectB n ;yPrimaryKey(id);
return item;
}
}
<!-- 配置包扫描器,扫描所有带@Service注| & n解的类 -->
<con@ B 2 ; P c 2text:component-scan base-package="com.taotao.service"/>
<!-- 发布dubbo服务 -->
<!-- 提供方应用信息,用于计算依赖关系 -->
<dubbo:appliH Z } ~ jcation name="taotao-manager" />
<!-- 注册中心的地址 -->
<dubbo:registry p. 6 Z [ e ]rotocol="zookeeper" address="192.168.* N { X m25.167:2181" />
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo" port="20880" />
<!a R F i V :-- 声明需要暴露的服务接口 -->
<dubbo:service intF P  L 5 @ 8 Y Cerface="com.taotao.service.ItemService" ref="itemServiceImpl" t7 c b s b t R j Gimeout="300000"/>

3、项目预览:
Spring+SpringMVC+Mybatis dubbo整合 bean实例化失败
4、异常全信息:

9月 08, 2020 10:34:26 上午 org.apache.coyote.AbstractProtocol init
信息: Initializingg s @ [ ProtocolHandQ p u Yler ["http^ 8 O B G i l 9-bio-8080"]
9月 08, 2020 10:34:26 上午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Tom% 0 p . c b [ Icat
9月 08, 2020 10:34:26 上午 org.ad : | = 9 x }pache.catalina.core.StandardEngine startInt6 ? } dernal
信息: Starting Servlet Ej ~ * o 9 f 6 l nngine: Apache Tomcat/7.0.4b W T j E7
9月 08, 2020 10:3X g | t h W4:29 上午 orgq } o j w C 7 x r.apache.catalina.core1 3 L L e _.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
9月 08, 2020 10:34:29d _ , ` 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring ro7 d = m O f Aot WebApplicationContext
log4j:WARN No appenders could be fou7 h / f a :nd for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Pleu Q D ase initialize thJ 6 r oe log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
9月 08, 2020 10:34:30 上午 org.apache.catalina.core.StandardContext listenerStart
严重: Exo r ) 4 4ception sending context initialized event to listener i$ N ) * znstance of class or? S L R D ? ]g.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creaA & ? * 2 i 6 1 ting bean with name 'com.taotao.serv^ n } A M uice.r 1 8 @ItemService': Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError
at org.spring 2 Gframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateB7 I V 9 u k %ean(AbstractE : L _ v p tAutowireCapableBeanFactory.java:1105)
at org.springframework.beans.factory.support.AB $ _ J Y . [ bbstractAutowiF p q r c 6 c u mreCat y P ~ T hpableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050)
at org.sp, ) , c F n ! bringframework.beans.factory.support.AbstractAutowireCaq K # E + ` F ypableBeanFactory.doCreateBean(AbstractAutowireCap{ a ] P 5 6 A 7ableBeanFactory.java:510)) w q 6 _ w . f X
at org.sF d h B tpringframework.beans.factory.suppor, 4 ~ M f ? T )t.AbstractAutowireCa$ r ` G & F ; ] hpableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingleto_ ? V D j KnBeanRegistry.getSin$ c N N 5 T igleton(DefaultSingletonBeanRegistry.java:230)
at org.s; ~ i T 8 U u s Epringframework.beans.factor| 7 k a o *y.support.AbstractBeanFactory.doGB # 8 :etBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factoR : T -  u 0 3 Ury.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.bear j A s A : - .ns.factory.support.D` 4 F vefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.m z ! Ljava:772)
at org.springframework.context.support.AbstractApplicn G U = ;ationCont* l y + ( f H ~ext.finishBeanFactoryInitialization(AbstractApplicatioa o d X OnContext.java:839)
at org.springframZ q 7 W z 0 4 :ework.context.support.Aa i | g h cbstractApplicationContext.refresh(AbstractApplicationContext.java:5/ M * L d 3 &38)
at org.springfS ; i n ( 8 M D Cramework.web.context.ContextLoader.cG g O q 3 ( , X LonfigureAndRefreshWebApplicationContext(ContextLoader.java:446)
at org.springframework.web.con^ f R ( I H L R ctext.ContextLoader.initWebApplicationContext(ContextLoader.javl T m / |a:328)
at org.springframu ~ Q l Rework.web.context.ContextLoadeI 7 1 Y f 5 y [ |rListe2 ] L H 5 e / yner.contextInitialiZ M v v 7 1zed(ContextLoaderListener.java:107)
at org.aY ] & rpache.catalina.core.StandardContext.listenerStart(Stc 7 ^ HandardContext.java:4939)
at org.apache.cataJ 1 plina.core.StandardContY 2  1ext.startInternal(StandardContext.java:5434)
at org.ap- - {  K a Jache.catalina.util.LifecycleBase.start(LifecycleBase.j8 o H a w R 3 -ava:150)
at org.apache.catalina.core.ContainerBase$StartCH _ y { Y w - `hild.call(Conta3 : civ ; i f ~ w U ] DnerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.base/java.util.cos L r j 4 m 5 Uncurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.j m N m R I Oconcn z Wurrent.? G i F - lThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/jM a 5 Q ! 6 v : ]ava.util.concurrent.ThreadPoolExecutor$Worker.ruq b u =n(ThreadPoolExecutor.java:628)
at java.b_ d ~ - m E #ase/9 % N L . d gjava.ln m *ang.Thread.~ C Y = `run(Thread.java:830)
CaR ; Yused by: java.lang.ExceptionInInitializerError
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newF K { U ( U U gInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.new6 h WInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccesso( , $ } m + m h ]rImpl.newInstance(Delega5 7 k O Q xtingConstructorAccessorImpl.javaH t 4:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at j2 d 0 = b W m .aw  I a (va.baseS a 0 e ?/java.lang.r] T I B Peflect.Constructor.newInsta@ % Q . 7nce(Conx A a u Tstructor.jL Z ( M E e ^ D [ava:481)
at org.springframework.beans.BeanUtils.instantiateClass? G k {  c S(BeanUtils.java:147)
at org.f v v & N #springframework.beans.factory.support.SimpleInstaj K B + } U OntiationStrategy.in/ 0 _ } 3 ] I Gstantiate(SimpleInstantiationStrategy.java:89)
a- 4 = # B i !t org.springframework.beg Q   M Z N 5 #ans.factory.sup M % w K p ` 9 Cpport.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutA ) Y Vow} ( k 9ire( $ h 4 $ k ] + bCapableBeanFactoA 6 5 0 ~ry.java:1098)
... 22 more
Cauu k 4 h C R jsed by: java.lang.Ill= C i B k j s 1 !eE [ ( B J EgalStateException: fail to create adaptive instance: java.lang.IllegalStateException: Can not create adaptive extenstion interface com.alibaba.dubbo.rpc.Protocol, cd g 7 o 8 Gause: java.io.IOException: invalid constant type: 18
at com.alibaba.dubbo.commW B 0 0 ? % - v yon.extension.ExtensionLoader.g5 ? E u vetAdaptiveExtension(ExtensionLoader.java:459)
at com.al= S [ x ; J , ^ibaba.dubbo.config.ServiceConfig.<clinit>(ServiceConfig.java:60)
... 30 more
CausV  , h 8 k . Z med by: java.lang.IllegalSta m d 8 J / [ E FteException: Can notz E A [ k B 5 + b create adaptive extenstion interface com.4 C N 2 P ~ z U ~ali3 6 T B 2 d S Qbaba.dubbo.rpc.Protocol, caM B ? N quse: javaO S ) h n g x.io.IOException: invalid constant type: 18
at com.alibaba.dubbo.common.extension.ExtensionLoader.createAdaptM q Q , H @iveExtens@ V 6 p m | m @ Rion(Extensiq 3 l x S # & F 3onLoader.java:723)
at com.alibaba.dubbo.common.extension.ExtensionLoader.getAdaptiveExtension(ExtensV d - `ionLoader.java:455)
.o y z I 8 z 0 U 1.. 31 more
Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18
at javassist.CtClassTyD 0 t q m o b d 6pe.getClassFile2(CtClassTypeu 5 u e b P 7 j f.java:# ~ , D { y T D 5204)
at javassist.CtClR d 9 % 0 E R Z fassType.subtypeOf(CtClassType.java:304)
at javassist.compiler.MemberResolver.compareSignature(MemberResolver.java:248)
at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:120)
at javassist.compiler.MemberRe^ S K Ysolver.lookupMethod(MemberR] A e n H |esolver.javD N g P w 2 oa:97)
aR x 6 1 c B Zt javassist.compiler.MemberCodeGen.atMethodCallCore(MemberCodeGen.java:562)
at javassist.compil2 , Q P * Oer.MemberCodeGen.atCallExpr(MemberCodeGen.java:524)
at javassist.compiler.JvstCodeGen.atCallExpr(JvstCodeGen.jav( 7 1 Z L c *a:244)
at javassist.compilerV _ a o ! 2 a * R.ast.CallExpr.accept(CallExpr.java:46)
at javassist.compiler.MemI | ] D j # HberCodeGen.atCald ` R HlExpr(MemberCodeGen.java:497)
at javK 2 , _ 7assist.compiler.JvstCodeGen.atCallExl Q x $ bpr(JvstCodeGen.java:244)@ Z x P Y ~
at javassis9 y / MtD . l.compiler.ast.CallExpr.accept(CallExpr.java:46)
at javassist.compiler.MemberCodeGen.atCallExpr(MemberCodeGen.java:497)
at javassist.compiler.JvstCodeGen.atCallExpr(JvstCodeGen.java:244)
at javassin L Wst.c ? y Lcompiler.ast.CallExpr.accept(CallExpr.java:46)
at javassist.cp Z ! O k +ompiler.MemberCodeGen.atCallExpr(MemberCodeGen.java:497)
at javassistN ` y , % k O } y.compiler.JvV T Q W P L . @ MstCodeGen.atCallExpr(JvstCodeGh 0 k ; 9 gen.java:244)
at javassist.compilg T / Ser.ast.CallExpr.accept(CallExpr.java:46)
at javassist.compiler.CodeGen.atBinExpr(CodeGen.java:966 } _ O T | j4)
at javassist.compiler.ast.BinExpr.accept(BinEz @ ? U . { | ?xpr.java:41)
at javassist.compilerC / A = .JvstCodeGen.atMethodArgs(JvstCodeGen.java:358)
at javassist.compiler.MemberCodeGen.atMethodCallCore(MemberCodeGen.java, h A P o ] ` K:556)
at javassist. i Z Y  #compiler.MemberCodeGen.atNewExpr(MemberCodeGen.java:302)
at javassist.compiler.ast.NewExpr.accept(NewExpr.java:73)
at javassist.comp$ ! 2 E a Yiler.CodeGen.compileExpr(CodeGen.java:230)
at jay T yvassist.coL & m G ;mpiler.CodeGen.atThrowStmnt(CodeGen.ja? e e N $ = } * Ava:628)
at javassist.compiler.CodeGen.atStmnt(CodeGeS % + N a ;n.java:365)
at javassist.compiler.0 f F W u m ]ast.Stmnt.accept(Sp J / ? l n ]tmnt.java:50)
at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:391) 9 A _ c F Y)
at javassist.% y $ h Y i $ Fcompiler.CodeGe[ o + m ( - n An.at{ M ; ] s % m KStmnt(CodeGen.e m 2 i 9 V java:355)
at javassist.compiler.ast.Stmnt.D n B c C J / 1 accept(Stmnt.java:50)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:351)
at javassist.compile! a t $ Ur.ast.Stmn* D `t.accL - 7 Sept(Stmnt.java:50)
at javas{ k b U = .  I Xsist.compiler.CodeGen.atMethodBody(CodeGen.java:292)
at javassist.compo t s Y u g ; n Ciler.CoV D  V [ i + : deGen.atMethodDecl(CodeGen.java:274)
at javassist.compiler.ast.MethodDecl.accept(MethodDecl.java:44)
at javassist.compiler.Javac.compileMethod(Javac.java:169)
at javassist.compX i 6 ! 6 K ` h :iler.Javac.compile(Javac.java:95)
at javas B T Us6 4 ( j Q 8ist.k 0 L 0CtNewMethod.make(CtNewMethod.java:74)
at javassisY 8 ` Mt.CtNewMethod.make(CtNewMethod.# T 3 w ) |java:45)
at com.alibaba.dubbo.common.compiler.support.JavassistCompiler.doCompile(JavassistCompiler.7 J . g zjava:119)
at com.alibaba.dubbo.common.compileA - Ur.support.AbstractCompiler.compile(Abstrf Y *actCom_ _ s C 5 9 @piler.java:59)
at com.alibaba.dubbo.common.compiler.support.AdaptiveCompiler.compile(AdaptiveCompiler.java:46)
at com.alibaba.dubbo.com; X I tmon.extension.ExtensionLp z { ^ } *oader.createAdaptiveExtensionClass(ExtensionLoader.java:739)
at com.alibaba.dubbo.l U ) ;  icommon.extension.ExtensionLoader.getAdaptiveExtensionClass(ExtensionLoader.java:732)
at com.alibaba.dubbo.common_ 6 C n w l 6 U F.Y C c ^extension.ExtensionLoader.createAdaptiveExtensioC M U Xn(ExtensionLoader.java:721)
... 32 more
Caused by: java.io.IOException: invalid constant type: 18
at jz d t I Havassist.bytecode.ConstPool.readOne(ConstPool.java:1113)
at javassist.bytecode.ConstPool.read(ConstPool.java:1056)
at javassist.bytecode.ConstPoo, 3 0 = l bl.<init>(ConstPool.java:150)
at javassist.bytecode.ClassFile.read(ClasL 0 ,  q o 4 o (sFile.java:765)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:109)
at javassist.CtClassTyp$  0 Ge.getClassFile2(C ~ m ftClassType.java:191)
... 77 more
9月 08,H ; X ` , 9 j ] 2020 10:34:30 上午 org.apache.catalina.corew + (.StandardContext startInternal
严重: Error listenerStart
9月 08, 2020 10:34:31 上午 org.apache.catalina.util.SessionIdGenerator createSecureRandom
信息: Creation of SecureRandom instan( L O R X Yce for session ID generation using [SHA1PRNG] took [511] milliseconds| = ? j v F.
9月 08, 2020 10:34:31 上午 org.apache.catalina.core.StandardContext startInternal
严重: ConteC g R Rxt [] startup failed due to previous errors
9月 08, 2020 10:34:31 上午 org.apache.catalina.core.ApplicationContext log
信息: Closing Spring root WebApplicationContext
9月 08, 2020 10:34:; b N ) m P31 上午 org.apache.catalina.loadX b u ser.WebappClassLoader clearReferencesJdbc
严重: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. TA z / 4 Do prevent a memory~ P 9 = ! g Z T leak, the JDBC Driver has been forcibly u: p 5 W nregistered.
9月 08, 2020 10:34:31 上午 org.apache.catalina.loader.WebappClassLoader clearRefO 2 W ` aerencesJdbc
严重: The web application [] registered the JDBC driver [com.mysql.fabric.jdbc.FabricMySQLDriver] but failed to unregister it when the weY G X ; 1 $ 2 Mb appl6  $ o d W f J pication was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregiP K & Rst! U ! ~ q Hered.
9月 08, 2020 10:34:31 上午 org.apache.catalina.loader.WebappClassr e a m M D x vLoader ce { ` zlearReferencesJdbc
严重: The web application [] registered the JDBC driver [com.alibaba.druiF { z @ Z b @ a ~d.proxy.DruidDriver] but faileH d vd to ug 1 Tnregister it when the web applicq a 9 S ,ation was s0 ` Ltopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
9] r g B & )月 08, 2020 10:34:31 上午 org.apache.catalina.loader.WebappClassLoader cleaU a @ % l o z zrReferencesJdbc
严重: The web application [] registered the JDBC driver [com.alibaba.dru _ } } y Q ; ( |id.mock.MockDriver] but failed to unregist% : _er it when the w7 { 0 %eb application was stopped. To prevent a memory= 0 3 ; y p ~ , s leak, the JDBC Driver has been fo J iorcibly un2 i gregistered.
9月 08, 2020 10:34:31 上午 org.apache.catalina.loader.WebappClassLt = 8 6 a X 4 p zoader clearReferencesThreads
严重: The web application [] appears to have started a thread name? P [ O Bd [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
WARNING: An illegal reflective access operat- g * l Uion has occurred
WARNING: Illegal reflective access by org.aF _ P Y b z N & rpachq  M ( a { e L Ge.catalina.loader.WebappClassLoader (file:/E:/JAVA/Mavex & 5 ? / nn/MavenHome/Reposito t d uory/org/apache/tomcat/embed/tomcat-embed-ce w | t N / a ore/7.0.47/tomcat-! 7 4 A c b 9 Pemh 7 / ` Kbed-core-7.0.47.jar) to field java.lang.Thread.threadLocals
WARNING: Px @ d ] 8  1lease consideB E Z  vr reporting this to the9 = g F maintainers of org.apache.catalina.loader.WebappClassLoader
W, ? } R 5 * _ 3ARNING: Use --illegal-access=warn to enable warnings of further illegal reflective aj u Y a Rccess operations
WARNING: All illegal access operaA T ; u D ^tions will be denied in a future release] b 1 $ @
9月 08, 2020 10:34:31 上午 org.apache.coyote.Abstr6 b v CactProtocol start
信息: Starting ProtocolHandler ["http-bio-8080"]

回答

你的配置中

<dubbo:se- [ c ! Nrvice interface="com.taotao.service.ItemService" ref="itemServiceImpl" timeout="300000"/>

这里的ref指向的是spring管理的bean名称,你的 @Service(, 9 O m 0"ItemService") ,这里声明的就是它的c - - j M G , q $名称,改为 @So T c . k 8 N :ervice(3 : q Y w s H /"itemServiceImpl") 试试。
如果不行,你把| h 2 D G X ! A异常信息截全发上来,看看是不是DAO层创建失败造成的service创建失败,通常异常是由外向里抛的