web-dev-qa-db-ja.com

ドライバークラスをロードできません:GradleとSpring Bootでcom.mysql.jdbc.Driver

私の問題は次のとおりです。 JDBC、Gradle、Springフレームワークの使い方を学んでいます(これらのテーマは初めてです)。私は次の example を実装しようとしていますが、1つの違いがあります。PostgreSQLではなくMySQLデータベースです。

タイトルで指定したように、アプリケーションは次のエラーで終了しますCannot load driver class: com.mysql.jdbc.Driver(投稿の最後のスタックトレース)。

もちろん、私はこの質問を投稿する前にグーグルで読んでいて、それを見つけましたcom.mysql.jdbc.Driverは、プログラムのローダーを使用してロードするか、Gradleビルドスクリプトを使用してロードすることもできます。

私の質問は次のとおりです。

  1. 著者の例がローダーなしで(プログラム内またはビルドスクリプト内で)機能する理由
  2. ローダーが絶対に必要な場合、それを実装する方法を簡単に説明できますか?

私が変更したbuild.gradleファイル:

buildscript { 
    repositories { 
        maven { url "http://repo.spring.io/libs-snapshot" } 
    } 
    dependencies { 
        classpath("org.springframework.boot:spring-boot-gradle-plugin:0.5.0.M6") 
        classpath 'mysql:mysql-connector-Java:5.1.34'  
    } 
} 

apply plugin: "Java" 
apply plugin: "spring-boot" 

buildDir = "out" 

jar { 
    baseName = "sb-jdbc" 
    version = "0.1" 
} 

repositories { 
    mavenCentral() 
    maven { url "http://repo.spring.io/libs-snapshot" } 
} 

dependencies { 
    def springBootVersion = '1.0.0.RC1'
    compile("org.springframework.boot:spring-boot-starter-jdbc:$springBootVersion")
    compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
    compile("org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion")
    compile("mysql:mysql-connector-Java:5.1.34")

    testCompile("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
    testCompile("junit:junit:4.11")
} 

ぼくの application.propertiesファイル:

spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost/:3306/******
spring.datasource.username=root
spring.datasource.password=******

# Specify the DBMS
spring.jpa.database = MYSQL

# Show or not log for each sql query
spring.jpa.show-sql = true

# Hibernate settings are prefixed with spring.jpa.hibernate.*
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.naming_strategy = org.hibernate.cfg.ImprovedNamingStrategy

スタックトレース(フルではない):

2015-01-03 20:09:20.203  WARN 10298 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected org.springframework.jdbc.core.JdbcTemplate demo.UserRepository.jdbc; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is Java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.Java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1202)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.Java:762)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.Java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.Java:480)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.Java:109)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.Java:691)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:321)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:961)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:950)
    at demo.WebBindGradleApplication.main(WebBindGradleApplication.Java:14)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke(Method.Java:606)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.Java:53)
    at Java.lang.Thread.run(Thread.Java:745)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: protected org.springframework.jdbc.core.JdbcTemplate demo.UserRepository.jdbc; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is Java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.Java:558)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.Java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.Java:331)
    ... 22 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is Java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.Java:334)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.Java:1202)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:193)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.Java:371)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.Java:1111)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.Java:1006)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.Java:1127)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.Java:1051)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.Java:949)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.Java:530)
    ... 24 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$JdbcTemplateConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is Java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.Java:558)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.Java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.Java:331)
    ... 44 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is Java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.Java:602)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.Java:1111)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.Java:1006)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.Java:504)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.Java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.Java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.Java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.Java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.Java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.Java:1127)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.Java:1051)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.Java:949)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.Java:530)
    ... 46 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is Java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.Java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.Java:591)
    ... 58 common frames omitted
Caused by: Java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver
    at org.springframework.util.Assert.state(Assert.Java:385)
    at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.Java:122)
    at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.Java:116)
    at Sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at Sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.Java:57)
    at Sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.Java:43)
    at Java.lang.reflect.Method.invoke(Method.Java:606)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.Java:162)
    ... 59 common frames omitted

2015-01-03 20:09:20.254  INFO 10298 --- [           main] o.Apache.catalina.core.StandardService   : Stopping service Tomcat
2015-01-03 20:09:20.308  INFO 10298 --- [           main] .b.l.ClasspathLoggingApplicationListener : Application failed to start with classpath: [jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-boot-starter-web-1.2.0.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-boot-starter-jdbc-1.2.0.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-boot-starter-1.2.0.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-boot-starter-Tomcat-1.2.0.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/jackson-databind-2.4.4.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/hibernate-validator-5.1.3.Final.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-core-4.1.3.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-web-4.1.3.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-webmvc-4.1.3.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-jdbc-4.1.3.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/Tomcat-jdbc-8.0.15.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-tx-4.1.3.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-boot-1.2.0.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-boot-autoconfigure-1.2.0.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-boot-starter-logging-1.2.0.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/snakeyaml-1.14.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/Tomcat-embed-core-8.0.15.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/Tomcat-embed-el-8.0.15.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/Tomcat-embed-logging-juli-8.0.15.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/Tomcat-embed-websocket-8.0.15.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/jackson-annotations-2.4.0.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/jackson-core-2.4.4.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/validation-api-1.1.0.Final.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/jboss-logging-3.1.3.GA.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/classmate-1.0.0.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-aop-4.1.3.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-beans-4.1.3.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-context-4.1.3.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/spring-expression-4.1.3.RELEASE.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/Tomcat-juli-8.0.15.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/jcl-over-slf4j-1.7.7.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/jul-to-slf4j-1.7.7.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/log4j-over-slf4j-1.7.7.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/logback-classic-1.1.2.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/aopalliance-1.0.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/slf4j-api-1.7.7.jar!/, jar:file:/home/pucek/Documents/workspace-sts-3.6.3.RELEASE/WebBindGradle/build/libs/demo-0.0.1-SNAPSHOT.jar!/lib/logback-core-1.1.2.jar!/]
2015-01-03 20:09:20.308  INFO 10298 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report enabled debug logging (start with --debug)


2015-01-03 20:09:20.310 ERROR 10298 --- [           main] o.s.boot.SpringApplication               : Application startup failed

アドバイス、説明、共有された例などを事前にありがとう!乾杯!

#1を編集

Kamoor氏が親切に提案したように、ローカルの* jarファイルが不足しているという問題があるかもしれません。手動で追加しない場合は、Gradleがリポジトリから自動的にダウンロードするのではないかと思いました(STSで作業しています)。ここで、mysql-connector-Java jarが存在することがわかります。

We can see Driver class for com.mysql.jdbc.DriverAnd here we can see that the mysql-connector-Java jar is added

それらのスクリーンショットをごめんなさい。私がそれを追加したことを示す他の方法がわからないだけです(私はEclipseに慣れていません)。

7
Marek

私は試行錯誤でこれを解決しました。私にとってそれは、ドライバー参照フォームのapplication.propertiesファイルを削除することでした。したがって、私のapplication.propertiesファイルは次のようになり、エラーはすぐになくなりました。

spring.datasource.url = jdbc:mysql://localhost:3306/test
spring.datasource.username = root 
spring.datasource.password = fake
#spring.datasource.driver-class-name = com.mysql.jdbc.Driver 
mybatis.config=mybatis-config.xml
mybatis.check-config-location=true

アプリケーションコード自体ではなく、組み込みのTomcatにそのドライバーが必要になる可能性に関係していると思います

8
Bostone

私の場合は特別ですが、私が見つけたものを他の人に知らせる必要があります。

私の場合、-brewでgradleをインストールしました、gradleのバージョンは2.1(今でも)-問題:com.mysql.jdbc.Driverクラスが見つかりません

私は多くの方法を試しましたが、最後に問題を解決しました:Gradleをアップグレードします(たとえば、3.3)。

  • gradleをアップグレードする
  • 再度gradle init(build.gradleとsettings.gradleを削除)
  • 古いビルド/設定から新しいビルド/設定まですべてをコピーする

そしてそれは働いた。

1
user7399910

これをpom.xmlに追加します。

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-Java</artifactId>
<version>5.1.27</version>
</dependency>

次に、application.propertiesを確認します

1
huster

@EnableAutoConfigurationにより、適切なBeanが確実にロードされます。ここでは、Springブートによってドライバーがロードされます。 ドキュメント を参照

あなたの場合、MySQLドライバのjarファイルがクラスパスに含まれていないので、SpringはDriverクラスを見つけることができません。ログで「ClasspathLoggingApplicationListener」を検索して、アプリケーションを実行するためにすべてのjarが含まれていることを確認します。

0
kamoor