경고 : 초보자 경보!Spring 초보자를위한 Spring MVC 프로젝트의 클래스로드 오류
나는 봄을 배우는 초기 단계에 있으며, DB에서 일부 데이터를 읽고 표시하는 첫 번째 앱을 시작하려고합니다.
저는 SpringSource Tool Suite 2.8.0.RELEASE를 사용하고 있습니다. 새로운 Spring MVC 프로젝트를 만들고 로컬 MySQL DB에서 일부 데이터를 읽으려고합니다. 내가 pom.xml 파일이 추가되었습니다
package com.blah.blah;
import org.springframework.jdbc.core.support.JdbcDaoSuppo rt;
public class MyDAO extends JdbcDaoSupport {
: 나는 루트의 context.xml이를 추가 한
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
(
나는 간단한 DAO 클래스를 썼다 이 업데이트 할 수있는 권한 설정 파일입니다) :<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>
내가 프로젝트를 마우스 오른쪽 버튼으로 클릭하고 디버그를 선택하면> 서버에서 디버그 나는 에로를 얻을 수 r :
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 클래스 파일을 볼 수 있으므로 왜 위의 오류가 발생하는지 알 수 없습니다.
큰 호응을 얻었습니다.
root-context.xml 파일에서'org.springframework.jdbc.datasource.DriverM anagerDataSource'의 빈 공간을 복사해서 붙여 넣으시겠습니까? –
그래, 그냥 복사해서 붙여 넣기 만하면 돼. 수정 됨. – CodeClimber
CTRL + SHIFT + T를 사용하여 STS에서 누락 된 클래스를 열어 본 다음 이름을 입력하고 클래스 경로에 있는지 확인하십시오. –