Java ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16477866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
提问by JuniorDev
I was trying to do some basic database operations. I'm using STS 3.2.0, Apache Tomcat 7.
我试图做一些基本的数据库操作。我正在使用 STS 3.2.0、Apache Tomcat 7。
My dispatcher-servlet.xml includes:
我的 dispatcher-servlet.xml 包括:
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/mydb" />
<property name="username" value="root" />
<property name="password" value="root" />
</bean>
Apache Tomcat fails miserably with thousands of exceptions, starting with this one :
Apache Tomcat 悲惨地失败了,出现了数以千计的异常,从这个开始:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource] for bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
Related cause: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource] for bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource
EDIT 1:I also downloaded 3.0.3.RELEASE version of the jar, and its still the same.
编辑 1:我还下载了 3.0.3.RELEASE 版本的 jar,它仍然是一样的。
FINAL EDITIt seems, you should add your external jar files manually to your deployment directory as well (well if you don't use any extension that'd do that for you)
最终编辑看来,您也应该手动将外部 jar 文件添加到部署目录中(如果您不使用任何可以为您执行此操作的扩展程序)
采纳答案by Patison
Try to add to POM.xml:
尝试添加到 POM.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
回答by Enrico
I think you should import selected jdbc jar into web app library.
我认为您应该将选定的 jdbc jar 导入到 Web 应用程序库中。
回答by ashish pandey
if none of the above solution doesn't work, then manually add spring-jdbc jar file to webapp/WEB-INF/lib.
如果上述解决方案均无效,则手动将 spring-jdbc jar 文件添加到 webapp/WEB-INF/lib。