警告: 初心者注意!
私はSpringを学び始めたばかりで、最初のアプリを起動して実行しようとしています。これは、DBからデータを読み取って表示するだけです。
SpringSource Tool Suite 2.8.0.RELEASE を使用しています。新しい Spring MVC プロジェクトを作成し、ローカルの MySQL DB からデータを読み取りたいと考えています。
簡単なDAOクラスを書きました:
package com.blah.blah;
import org.springframework.jdbc.core.support.JdbcDaoSuppo rt;
public class MyDAO extends JdbcDaoSupport {
これを pom.xml ファイルに追加しました。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
これを root-context.xml に追加しました (これは更新する正しい構成ファイルですか?):
<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>
プロジェクトを右クリックして [Debug As] > [Debug On Server] を選択すると、次のエラーが表示されます。
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
私はこれをしばらく見てきましたが、何が間違っているのかわかりません。アプリがデプロイされているフォルダーを見つけました (C:\Program Files\springsource\vfabric-tc-server-developer-2.6.1.RELEASE\spring-insight-instance\wtpwebapps\MyAppName\WEB-INF\lib lib フォルダーには spring-jdbc-3.1.0.RELEASE.jar が含まれており、それを開くと DriverManagerDataSource クラス ファイルが表示されるため、上記のエラーが発生する理由がわかりません。
アドバイスをいただければ幸いです。