fenghuashao
2020-09-08 00:27
采纳率: 66.7%
浏览 180
已采纳

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 creating bean with name 'com.taotao.service.ItemService': Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError

2、代码片段:

package com.taotao.service;
import com.taotao.pojo.TbItem;

public interface ItemService {
    TbItem getItemById(long id);
}

package com.taotao.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.taotao.mapper.TbItemMapper;
import com.taotao.pojo.TbItem;
import com.taotao.service.ItemService;
//@Service("itemService")

@Service("ItemService")
public class ItemServiceImpl implements ItemService {

    @Autowired
    private TbItemMapper itemMapper; 

    @Override
    public TbItem getItemById(long id) {
        // TODO Auto-generated method stub
        TbItem item = itemMapper.selectByPrimaryKey(id);
        return item;
    }

}   
    <!-- 配置包扫描器,扫描所有带@Service注解的类 -->
    <context:component-scan base-package="com.taotao.service"/>

    <!-- 发布dubbo服务 -->
    <!-- 提供方应用信息,用于计算依赖关系 -->
    <dubbo:application name="taotao-manager" />
    <!-- 注册中心的地址 -->
    <dubbo:registry protocol="zookeeper" address="192.168.25.167:2181" />
    <!-- 用dubbo协议在20880端口暴露服务 -->
    <dubbo:protocol name="dubbo" port="20880" />
    <!-- 声明需要暴露的服务接口 -->
    <dubbo:service interface="com.taotao.service.ItemService" ref="itemServiceImpl" timeout="300000"/>

3、项目预览:
图片说明
4、异常全信息:

9月 08, 2020 10:34:26 上午 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8080"]
9月 08, 2020 10:34:26 上午 org.apache.catalina.core.StandardService startInternal
信息: Starting service Tomcat
9月 08, 2020 10:34:26 上午 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/7.0.47
9月 08, 2020 10:34:29 上午 org.apache.catalina.core.ApplicationContext log
信息: No Spring WebApplicationInitializer types detected on classpath
9月 08, 2020 10:34:29 上午 org.apache.catalina.core.ApplicationContext log
信息: Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the 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
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.taotao.service.ItemService': Instantiation of bean failed; nested exception is java.lang.ExceptionInInitializerError
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1105)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1050)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:446)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:328)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.ExceptionInInitializerError
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1098)
    ... 22 more
Caused by: java.lang.IllegalStateException: fail to create adaptive instance: java.lang.IllegalStateException: Can not create adaptive extenstion interface com.alibaba.dubbo.rpc.Protocol, cause: java.io.IOException: invalid constant type: 18
    at com.alibaba.dubbo.common.extension.ExtensionLoader.getAdaptiveExtension(ExtensionLoader.java:459)
    at com.alibaba.dubbo.config.ServiceConfig.<clinit>(ServiceConfig.java:60)
    ... 30 more
Caused by: java.lang.IllegalStateException: Can not create adaptive extenstion interface com.alibaba.dubbo.rpc.Protocol, cause: java.io.IOException: invalid constant type: 18
    at com.alibaba.dubbo.common.extension.ExtensionLoader.createAdaptiveExtension(ExtensionLoader.java:723)
    at com.alibaba.dubbo.common.extension.ExtensionLoader.getAdaptiveExtension(ExtensionLoader.java:455)
    ... 31 more
Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18
    at javassist.CtClassType.getClassFile2(CtClassType.java:204)
    at javassist.CtClassType.subtypeOf(CtClassType.java:304)
    at javassist.compiler.MemberResolver.compareSignature(MemberResolver.java:248)
    at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:120)
    at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:97)
    at javassist.compiler.MemberCodeGen.atMethodCallCore(MemberCodeGen.java:562)
    at javassist.compiler.MemberCodeGen.atCallExpr(MemberCodeGen.java:524)
    at javassist.compiler.JvstCodeGen.atCallExpr(JvstCodeGen.java:244)
    at javassist.compiler.ast.CallExpr.accept(CallExpr.java:46)
    at javassist.compiler.MemberCodeGen.atCallExpr(MemberCodeGen.java:497)
    at javassist.compiler.JvstCodeGen.atCallExpr(JvstCodeGen.java:244)
    at javassist.compiler.ast.CallExpr.accept(CallExpr.java:46)
    at javassist.compiler.MemberCodeGen.atCallExpr(MemberCodeGen.java:497)
    at javassist.compiler.JvstCodeGen.atCallExpr(JvstCodeGen.java:244)
    at javassist.compiler.ast.CallExpr.accept(CallExpr.java:46)
    at javassist.compiler.MemberCodeGen.atCallExpr(MemberCodeGen.java:497)
    at javassist.compiler.JvstCodeGen.atCallExpr(JvstCodeGen.java:244)
    at javassist.compiler.ast.CallExpr.accept(CallExpr.java:46)
    at javassist.compiler.CodeGen.atBinExpr(CodeGen.java:964)
    at javassist.compiler.ast.BinExpr.accept(BinExpr.java:41)
    at javassist.compiler.JvstCodeGen.atMethodArgs(JvstCodeGen.java:358)
    at javassist.compiler.MemberCodeGen.atMethodCallCore(MemberCodeGen.java:556)
    at javassist.compiler.MemberCodeGen.atNewExpr(MemberCodeGen.java:302)
    at javassist.compiler.ast.NewExpr.accept(NewExpr.java:73)
    at javassist.compiler.CodeGen.compileExpr(CodeGen.java:230)
    at javassist.compiler.CodeGen.atThrowStmnt(CodeGen.java:628)
    at javassist.compiler.CodeGen.atStmnt(CodeGen.java:365)
    at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
    at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:391)
    at javassist.compiler.CodeGen.atStmnt(CodeGen.java:355)
    at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
    at javassist.compiler.CodeGen.atStmnt(CodeGen.java:351)
    at javassist.compiler.ast.Stmnt.accept(Stmnt.java:50)
    at javassist.compiler.CodeGen.atMethodBody(CodeGen.java:292)
    at javassist.compiler.CodeGen.atMethodDecl(CodeGen.java:274)
    at javassist.compiler.ast.MethodDecl.accept(MethodDecl.java:44)
    at javassist.compiler.Javac.compileMethod(Javac.java:169)
    at javassist.compiler.Javac.compile(Javac.java:95)
    at javassist.CtNewMethod.make(CtNewMethod.java:74)
    at javassist.CtNewMethod.make(CtNewMethod.java:45)
    at com.alibaba.dubbo.common.compiler.support.JavassistCompiler.doCompile(JavassistCompiler.java:119)
    at com.alibaba.dubbo.common.compiler.support.AbstractCompiler.compile(AbstractCompiler.java:59)
    at com.alibaba.dubbo.common.compiler.support.AdaptiveCompiler.compile(AdaptiveCompiler.java:46)
    at com.alibaba.dubbo.common.extension.ExtensionLoader.createAdaptiveExtensionClass(ExtensionLoader.java:739)
    at com.alibaba.dubbo.common.extension.ExtensionLoader.getAdaptiveExtensionClass(ExtensionLoader.java:732)
    at com.alibaba.dubbo.common.extension.ExtensionLoader.createAdaptiveExtension(ExtensionLoader.java:721)
    ... 32 more
Caused by: java.io.IOException: invalid constant type: 18
    at javassist.bytecode.ConstPool.readOne(ConstPool.java:1113)
    at javassist.bytecode.ConstPool.read(ConstPool.java:1056)
    at javassist.bytecode.ConstPool.<init>(ConstPool.java:150)
    at javassist.bytecode.ClassFile.read(ClassFile.java:765)
    at javassist.bytecode.ClassFile.<init>(ClassFile.java:109)
    at javassist.CtClassType.getClassFile2(CtClassType.java:191)
    ... 77 more

9月 08, 2020 10:34:30 上午 org.apache.catalina.core.StandardContext startInternal
严重: Error listenerStart
9月 08, 2020 10:34:31 上午 org.apache.catalina.util.SessionIdGenerator createSecureRandom
信息: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [511] milliseconds.
9月 08, 2020 10:34:31 上午 org.apache.catalina.core.StandardContext startInternal
严重: Context [] 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:31 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
9月 08, 2020 10:34:31 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [] registered the JDBC driver [com.mysql.fabric.jdbc.FabricMySQLDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
9月 08, 2020 10:34:31 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [] registered the JDBC driver [com.alibaba.druid.proxy.DruidDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
9月 08, 2020 10:34:31 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
严重: The web application [] registered the JDBC driver [com.alibaba.druid.mock.MockDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
9月 08, 2020 10:34:31 上午 org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
严重: The web application [] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.catalina.loader.WebappClassLoader (file:/E:/JAVA/Maven/MavenHome/Repository/org/apache/tomcat/embed/tomcat-embed-core/7.0.47/tomcat-embed-core-7.0.47.jar) to field java.lang.Thread.threadLocals
WARNING: Please consider reporting this to the maintainers of org.apache.catalina.loader.WebappClassLoader
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
9月 08, 2020 10:34:31 上午 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8080"]

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 烟雨虹 2020-09-08 10:00
    已采纳

    你的配置中

    <dubbo:service interface="com.taotao.service.ItemService" ref="itemServiceImpl" timeout="300000"/>
    

    这里的ref指向的是spring管理的bean名称,你的 @Service("ItemService") ,这里声明的就是它的名称,改为 @Service("itemServiceImpl") 试试。
    如果不行,你把异常信息截全发上来,看看是不是DAO层创建失败造成的service创建失败,通常异常是由外向里抛的

    打赏 评论
  • dabocaiqq 2020-09-08 08:27
    打赏 评论

相关推荐 更多相似问题