sinat_39560577
sinat_39560577
2018-02-06 12:21
采纳率: 50%
浏览 1.2k
已采纳

这个项目为什么启动报错,什么原因呢?

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [jar:file:/D:/Develop/repository/com/taotao/taotao-manager-dao/0.0.1-SNAPSHOT/taotao-manager-dao-0.0.1-SNAPSHOT.jar!/spring/applicationContext_dao.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis/SqlMapConfig.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
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:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
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.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.core.NestedIOException: Failed to parse config resource: class path resource [mybatis/SqlMapConfig.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:434)
at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:340)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
... 21 more
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:109)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:92)
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:428)
... 24 more
Caused by: java.lang.ClassCastException: com.github.pagehelper.PageHelper cannot be cast to org.apache.ibatis.plugin.Interceptor
at org.apache.ibatis.builder.xml.XMLConfigBuilder.pluginElement(XMLConfigBuilder.java:142)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:100)
... 26 more

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

5条回答 默认 最新

  • jinjidechengxuyuan
    jinjidechengxuyuan 2018-02-06 13:44
    已采纳

    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [jar:file:/D:/Develop/repository/com/taotao/taotao-manager-dao/0.0.1-SNAPSHOT/taotao-manager-dao-0.0.1-SNAPSHOT.jar!/spring/applicationContext_dao.xml
    首先遇到这种问题,前面几行是对你来说最有用的,我们来分析一下,org.springframework.beans.factory.BeanCreationException:这句说明了springbean工厂无法创建相应的bean的实例,其次后面的 Error creating bean with name 'sqlSessionFactory' defined in URL 说明了一个相对具体的错误,也就是说在spring与数据库有关框架整合时出现了相应的错误无法生成sqlSessionFactory工厂对象,[jar:file:/D:/Develop/repository/com/taotao/taotao-manager-dao/0.0.1-SNAPSHOT/taotao-manager-dao-0.0.1-SNAPSHOT.jar!/spring/applicationContext_dao.xml而这个路径就是你创建的配置文件的对象的位置,我给你的建议是首先你要查看,个文件applicationContext.xml这,个文件就好像一个导演,它来分配每个角色具体干什么,你要确认applicationContext.xml文件中你的关于mybatis的配置是否有正确完成,包括里面配置好的数据库的内容,加入的包等等,进一步查看你的mybatis-config的文件内容。但是你这个问题我觉得是没有正确将spring容器与你的SqlMapConfig.xml整合好的问题,仔细查看一下。英文的报错的提示已经把问题出现的点说的比较具体了,以后出问题试着多看看报错的提示。

    点赞 评论
  • qq_38269781
    一触即发886 2018-02-06 12:31

    javabean配置文件路径有问题,根据提示路径和自己的对比下mybatis/SqlMapConfig.xml

    点赞 评论
  • chinauip
    chinauip 2018-02-06 13:41

    不是路径问题, 是mybatis分页插件配置错误

    点赞 评论
  • xcg132566
    同是天涯程序猿 2018-02-06 15:17

    创建bean 失败首先检查配置文件

    点赞 评论
  • ludanwss0716
    ludanwss0716 2018-02-06 15:42

    我也遇到了这个问题,解决方案:
    1、taotao-parent的pom.xml中把pagehelper的版本改为5.0.0,不用3.4.2-fix,然后保存,jar包会自动加载;
    2、这时点开taotao-manager-web里的maven dependencies目录下的com.github.pagehelper包,发现PageHelper.class并没有继承Interceptor接口,
    而是PageInterceptor.class继承了这个借口,所以将mybatis的配置文件SqlMapConfig.xml中的
    改成,同时因为pagehelper5以上的版本可以匹配任意数据库,所以将 这句删掉;
    3、此时会发现TestPageHelper中@Test报错,说找不到junit那个包,删掉这句即可。
    然后就可以运行taotao-manager啦

    点赞 评论

相关推荐