ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource (ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource)


問題の説明

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 JuniorDevPatisonEnricoashish pandey)

リファレンスドキュメント

  1. ClassNotFoundException: org.springframework.jdbc.datasource.DriverManagerDataSource (CC BY‑SA 3.0/4.0)

#spring-mvc #jdbc #java #classnotfoundexception






関連する質問

データを含むテキストボックスの値をSpringMVCコントローラーに渡す方法は? (How to pass textbox value which has the data to spring MVC controller?)

ファイルの静的フォルダーを参照できるようにする Spring MVC ビューはありますか? (Is there a Spring MVC view that allows me to browse a static folder of files?)

コンテンツ タイプが「text/html」の BirtView BeanNameViewResolver (BirtView BeanNameViewResolver with content type "text/html")

Quartz Spring 構成の xml とプロパティを @Configuration に置き換えます (Replace Quartz Spring configuration xml and properties with @Configuration)

Spring MVC データベース接続 (Spring MVC database connection)

spring mvc & hibernate バリデーター: 有効な json (spring mvc & hibernate validator: valid json)

Springを使ったオープンソースプロジェクト<中規模> (Open source project using Spring <Medium sized>)

同じプロパティ ApiImplicitParams に複数のカスタム アノテーションを使用する (Using Multiple Custom Annotations for the same property ApiImplicitParams)

「dietaController」という名前の Bean の作成中にエラーが発生しました (Error creating bean with name 'dietaController')

springboot のマッピング順序について (about springboot mapping order)

例外がサービスからスローされる残りのコントローラーで例外をモックする方法 (How to mock a exception in rest controller where the exception is thrown from a service)

MVC でファイルをアップロードする (Uploading file with MVC)







コメント