問題の説明
ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource (ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource)
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
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)
リファレンスソリューション
方法 1:
Try to add to POM.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring‑jdbc</artifactId>
<version>3.0.3.RELEASE</version>
</dependency>
方法 2:
I think you should import selected jdbc jar into web app library.
方法 3:
if none of the above solution doesn't work, then manually add spring‑jdbc jar file to webapp/WEB‑INF/lib.
(by JuniorDev、Patison、Enrico、ashish pandey)