2012-08-30 2 views
12

stackoverflow에서 여러 가지 유사한 질문을 본 적이 있지만 문제가 해결되지 않았습니다. This one은 공식 tomcat documentation 및 특별히 this section을 가리키므로 특히 유용합니다.tomcat7 : JDBC 드라이버 클래스 [com.mysql.jdbc.Driver]를로드 할 수 없습니다.

제공되는 솔루션은 간단합니다 : 에서 찾을 수 없기 때문에 tomcat은 $CATALINA_HOME/lib으로 복사 할 jdbc 데이터베이스 드라이버가 필요합니다. 좋아,하지만 여전히 나에게는 효과가 없으며 나는 화를 내고있다.

추가 아이디어를 제공해 줄 수 있는지 알아 보겠습니다.

환경은 입니다. Windows XP, Tomcat7, Eclipse Indigo, Java6 및 Spring3입니다.

mysql-connector이 ($CATALINA_HOME/lib

C:\>dir "c:\Program Files\Apache-Tomcat-7.0.12\lib"\mysql* 
[...] 
/2012 13:39   877.094 mysql-connector-java-5.1.21.jar 
[...] 
C:\> 

당신은 아마 이클립스의 톰캣 통합은 배포 (CATALINA_BASE)에 대한 WTP-특정 디렉토리를 생성 알고 복사, 그래서도 MySQL의 커넥터를 복사 된 나는 실패했습니다 지금까지 내가 Tomcat의 캘리포니아를 이해

C:\>dir c:\Share\genesis\wsEclipse-indigo\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\lib 
[...] 
29/08/2012 13:39   877.094 mysql-connector-java-5.1.21.jar 
[...] 
C:\> 

을 : CATALINA_BASE와 둘 다)에, CATALINA_HOME에서 mysql-conector.jar으로 시도 talina.properties 파일은 둘 다 classpath에 추가되었으므로 어떤 차이도 기대하지는 않았지만, 경우에 따라 시도했습니다.

내 스프링 소스의 정의는 매우 간단합니다 :

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

그러나 나는 다시 시작할 때 바람둥이 내가받을 다음과 같은 오류 :

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityDataSource' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: 
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1396) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701) 
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5204) 
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5199) 
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: 
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver] 
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102) 
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393) 
    ... 21 more 
30-ago-2012 8:38:11 org.apache.catalina.core.StandardContext listenerStart 
GRAVE: Excepción enviando evento inicializado de contexto a instancia de escuchador de clase org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityDataSource' defined in ServletContext resource [/WEB-INF/spring/root-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: 
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver] 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1396) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:585) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4701) 
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5204) 
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5199) 
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: 
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.mysql.jdbc.Driver] 
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:102) 
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1393) 
    ... 21 more 

이 하나 더 힌트 : 사용 시스 인 터널 프로세스 탐색기가 나는 것을 볼 수 mysql-connector-java.jar 톰캣에 의해 개방되고 있습니다 :

"C:\Program Files\Java\jre6\bin\javaw.exe" -Dcatalina.base=C:\Share\genesis\wsEclipse-indigo\.metadata\.plugins\org.eclipse.wst.server.core\tmp0 "-Dcatalina.home=C:\Program Files\Apache-Tomcat-7.0.12" -Dwtp.deploy=C:\Share\genesis\wsEclipse-indigo\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps "-Djava.endorsed.dirs=C:\Program Files\Apache-Tomcat-7.0.12\endorsed" -Dfile.encoding=Cp1252 -classpath "C:\Program Files\Apache-Tomcat-7.0.12\bin\bootstrap.jar;C:\Program Files\Apache-Tomcat-7.0.12\bin\tomcat-juli.jar" org.apache.catalina.startup.Bootstrap start 

Tomcat @ Process Explorer

더 이상의 아이디어?


EDIT1 : 나는 오라클을 사용하는 시도하고 그것을 작동합니다!

C:\>dir "c:\Program Files\Apache-Tomcat-7.0.12\lib"\oci* 
[...] 
02/10/2006 22:36   1.545.954 ocijdbc10.jar 
[...] 
C:\> 

데이터 소스 : 내가 MySQL을 잘못하고있는 중이 야 무엇

<bean id="securityDataSource" 
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> 
    <property name="url" value="jdbc:oracle:oci:@BARVDB002D:1545:TFSDB0" /> 
    <property name="username" value="me" /> 
    <property name="password" value="qwerty" /> 
    </bean> 

?

+1

:-(자신을 위해

Downvote 아래의 답변을 참조하십시오 –

+0

이 아이디어는 문제를 찾을 수있는 핵심이었다 간단한 자바 applicatoin 내에서 loding에게 동일한 드라이버를 시도 –

답변

9

가 해결 WEB-INF/lib/ 폴더를 응용 프로그램에서 파일을 넣어 시도 할 것이다는 $CATALINA_HOME/lib/에서 파일을 작동 방법을 알고

그러나 봄은 그 클래스를 Class.forName(driverClassNameToUse, true, ClassUtils.getDefaultClassLoader())를로드하는 특별한 방법을 사용하고 난 해달라고!

Arturs Licis의 제안이 핵심이었습니다. 어떻게 든 mysql 드라이버가 잘못 다운로드되었습니다. .jar 파일처럼 보이지만로드하지 못했습니다. 톰캣 예외 단지 처음 레벨 도시 하였다

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 
[...] 

을하지만 위해 Class.forName ("com.mysql.jdbc.Driver")가 매우 간단한 helloworld를 부호화 할 때, 다음과 같은 오류 대신 도시 하였다

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 
[...] 
Caused by: java.util.zip.ZipException: invalid LOC header (bad signature) 
[...] 

유레카! WinRar에서 .jar 파일을 열면 파일을 열 수 있지만 오류가 있습니다.

드라이버를 다시 다운로드하면 문제가 해결됩니다. ..? 감사합니다,하지만 난 :

+0

도움이 되었으면 다행입니다. –

3

The solutions provided there is, in short: tomcat needs jdbc database drivers to be copied to $CATALINA_HOME/lib/ , because it will not find them under WEB-INF/lib/ . Ok, but it still does not work for me, and I am becoming mad.

이것은 드라이버를로드하는 방법에 따라 다릅니다.

사용자가 tomcat 내에서 드라이버를 구성하고 응용 프로그램에 제공하면이 문이 올 바릅니다.

그러나 응용 프로그램 내에서 드라이버를 직접로드하십시오. 그렇다면 $CATALINA_HOME/lib/ (바람둥이에서)과 WEB-INF/lib/ (응용 프로그램에서) 두 가지 방법으로 작동합니다. 그래서

+0

랄프 되세요 Maven이 이미 WEB-INF/lib /에 아무런 변화없이 mysql-connector를 넣었고, 오라클을 이용한 테스트에서 편집을 참조하십시오 ... –

+0

그래야 문제가 해결 될 것입니다. – Ralph

+0

동의한다. 내가 mysql을 위해 특별히 잘못된 것을하고있는 것 같다. –

관련 문제