21

I was trying to do some basic database operations. I'm using STS 3.2.0, Apache Tomcat 7.

My dispatcher-servlet.xml includes:

<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 :

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

And these are my library definitions

EDIT 1: I also downloaded 3.0.3.RELEASE version of the jar, and its still the same.

FINAL EDIT It 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)

2
  • Is that class actually in the jar file (open it with winzip or expand it in eclipse). If not then you have the wrong jar. If it is there then you are not picking it up when you start your app. May 10, 2013 at 9:03
  • @DaveRlz I think it is in the jar. I can import and directly use its contents on my regular java files, it just does not seem to exist while my webapp is being started.
    – JuniorDev
    May 10, 2013 at 10:10

3 Answers 3

51

Try to add to POM.xml:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>3.0.3.RELEASE</version>
</dependency>
4
  • I've regenerated my pom.xml file and added jdbc dependency, but result is same.
    – JuniorDev
    May 10, 2013 at 10:53
  • 1
    does your war file contain that jar in WEB-INF/lib folder?
    – Patison
    May 10, 2013 at 11:33
  • 1
    well at least now I understand why I should use extensions like maven. The problem was, even though I added those jar to my project, they simply didn't exist in my WEB-INF/lib folder. I'll add these result to my original post, and select yours as an answer. Thanks!
    – JuniorDev
    May 10, 2013 at 11:42
  • check mvnrepository.com/artifact/org.springframework/spring-jdbc for latest version
    – prayagupa
    Apr 12, 2020 at 21:29
0

I think you should import selected jdbc jar into web app library.

0
0

if none of the above solution doesn't work, then manually add spring-jdbc jar file to webapp/WEB-INF/lib.

2
  • 3
    Try to expand on your answer a bit Jun 14, 2018 at 19:23
  • download spring-jdbc-5.0.2.RELEASE.jar and copy it, in webapp/WEB-INF/lib. this jar version may vary for your project. so download jar version which is suitable for your project Jun 14, 2018 at 19:42

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.