1

Warning: newbie alert!

I'm in early days of learning Spring and am trying to get my first app up and running which will simply read some data from a DB and display it.

I'm using SpringSource Tool Suite 2.8.0.RELEASE. I've created a new Spring MVC project and want to read some data from a local MySQL DB.

I wrote a simple DAO class:

package com.blah.blah;

import org.springframework.jdbc.core.support.JdbcDaoSuppo rt;

public class MyDAO extends JdbcDaoSupport {

I've added this to the pom.xml file:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>${org.springframework-version}</version>
</dependency>

I've added this to the root-context.xml (is this the right config file to update?):

<bean id="myDataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/dbname" />
    <property name="username" value="root" />
    <property name="password" value="mypw" />
</bean>

<bean id="jdbcTemplate"
    class="org.springframework.jdbc.core.JdbcTemplate" >
    <constructor-arg ref="myDataSource"></constructor-arg>
</bean>

<bean id="parentDAO"
    class="org.springframework.jdbc.core.support.JdbcD aoSupport">
    <property name="dataSource" ref="myDataSource"></property>
</bean>

When I right-click on the project and select Debug As > Debug On Server I get the error:

24-Mar-2012 16:13:42 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of 
class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.CannotLoadBeanClassException:
 Cannot find class [org.springframework.jdbc.datasource.DriverManagerDataSource] 
for bean with name 'myDataSource' defined in ServletContext resource 
[/WEB-INF/spring/root-context.xml]; nested exception is 
java.lang.ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource

I've been looking at this for a while and can't figure out what I'm doing wrong. I've found the folder where the app is deployed to (C:\Program Files\springsource\vfabric-tc-server-developer-2.6.1.RELEASE\spring-insight-instance\wtpwebapps\MyAppName\WEB-INF\lib on my machine) and the lib folder contains spring-jdbc-3.1.0.RELEASE.jar and when I open it, I can see the DriverManagerDataSource class file so I don't know why I'm getting the error above.

Any advice greatly appreciated.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
CodeClimber
  • 4,584
  • 8
  • 46
  • 55

4 Answers4

0

I had the same problem in Eclipse and creating a new workspace solved this problem.

Denis.Kipchakbaev
  • 970
  • 15
  • 24
  • 1
    Had the same problem in STS 3.3.0. spring-jdbc was in my pom, but tc Server kept saying org.springframework.jdbc.datasource.DriverManagerDataSource was not found. I didn't get this problem while I was developing on one machine, but when I imported my workspace into STS I got this problem. I did what Denis suggested and reinstalled STS, wiped out my maven repository, and re-created the workspace from scratch. Instead of importing the project, I created a new Spring MVC project and copied files into this new project and it worked. – Matt R Sep 07 '13 at 15:01
0

I had added required jar source instead of release. Strange but changing that to release version fixed this problem.

user17
  • 23
  • 5
0

Check that the Spring libraries are in the classpath so they are available for the server.

jddsantaella
  • 3,657
  • 1
  • 23
  • 39
0

I had the same jar file included in the project twice. Removed one and it worked.

CodeClimber
  • 4,584
  • 8
  • 46
  • 55