当前位置:   article > 正文

Spring-mybatis整合配置错误,显示不能创建spring配置文件中的sqlSessionFactory的Bean_在创建sqlsessionbean找不到配置文件

在创建sqlsessionbean找不到配置文件

 

 

type Exception report

message Servlet.init() for servlet springmvc threw exception

description The server encountered an internal error that prevented it from fulfilling this request.

exception

  1. javax.servlet.ServletException: Servlet.init() for servlet springmvc threw exception
  2. org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
  3. org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
  4. org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
  5. org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
  6. org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
  7. org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
  8. org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
  9. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  10. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  11. org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  12. java.lang.Thread.run(Thread.java:748)

 

root cause

  1. org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in ServletContext resource [/WEB-INF/springmvc-config.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
  2. PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy
  3. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1518)
  4. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
  5. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
  6. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
  7. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
  8. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  9. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
  10. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
  11. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)
  12. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:835)
  13. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
  14. org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)
  15. org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)
  16. org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)
  17. org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)
  18. org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)
  19. org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
  20. javax.servlet.GenericServlet.init(GenericServlet.java:158)
  21. org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
  22. org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
  23. org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
  24. org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
  25. org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
  26. org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
  27. org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
  28. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  29. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  30. org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  31. java.lang.Thread.run(Thread.java:748)

 

root cause

  1. org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
  2. PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy
  3. org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:121)
  4. org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
  5. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514)
  6. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226)
  7. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
  8. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
  9. org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
  10. org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
  11. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
  12. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
  13. org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:753)
  14. org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:835)
  15. org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
  16. org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)
  17. org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)
  18. org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)
  19. org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)
  20. org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)
  21. org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
  22. javax.servlet.GenericServlet.init(GenericServlet.java:158)
  23. org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
  24. org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
  25. org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
  26. org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
  27. org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
  28. org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
  29. org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
  30. java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  31. java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  32. org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  33. java.lang.Thread.run(Thread.java:748)

 

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.81 logs.

 

 

 

2.问题分析

上网查了之后发现是在对Spring数据源dataSource配置之后,运行程序出现如下错误:

java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy

原因是项目没有导入spring-jdbc的jar包。

 

如果使用maven,可以直接在pom.xml加入如下依赖:

 

  1. <dependency>
  2. <groupId>org.springframework</groupId>
  3. <artifactId>spring-jdbc</artifactId>
  4. <version>4.2.5.RELEASE</version>
  5. </dependency>
 

 

 

注:这是我遇到的问题NoClassDefFoundError:,是其中一个会导致这个问题的原因,还有其他的一些原因,可能包括mapper.xml的namespace,或者配置文件等原因.也有可能是jar包冲突,换换版本试试

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/898698
推荐阅读
相关标签
  

闽ICP备14008679号