web-dev-qa-db-fra.com

Impossible de charger la classe de pilote: com.mysql.jdbc.Driver avec Gradle et Spring Boot

Mon problème est le suivant. J'apprends à utiliser les frameworks JDBC, Gradle et Spring (je suis novice dans ces sujets). J'ai essayé d'implémenter le exemple avec une différence, la base de données MySQL au lieu de PostgreSQL.

Comme je l'ai spécifié dans le titre, mon application se termine par l'erreur suivante Cannot load driver class: com.mysql.jdbc.Driver (trace de pile à la fin du message).

Bien sûr, j’ai cherché sur Google et lu avant d’afficher cette question et j’ai trouvé que com.mysql.jdbc.Driver devrait être chargé à l’aide du programme loader dans le programme ou bien à l’aide du script de génération Gradle.

Mes questions sont les suivantes:

  1. Pourquoi les auteurs par exemple fonctionnent sans chargeur (soit dans le programme, soit dans le script de construction)
  2. Si le chargeur est absolument nécessaire, pouvez-vous expliquer brièvement comment le mettre en œuvre?

Mon fichier build.gradle modifié:

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")
} 

Mon fichier 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

Trace de pile (non pleine):

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

Merci d’avance pour tous conseils, exploanations, exemples partagés et cetera! À la vôtre!

Modifier # 1

Comme M. Kamoor l'a gentiment suggéré, le problème peut être le manque de fichier * jar local. Je pensais que Gradle le téléchargerait automatiquement à partir du référentiel, au cas où je ne l'aurais pas ajouté manuellement (je travaille sur STS). Nous pouvons voir ici que jar mysql-connector-Java est là.

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

Je suis désolé pour ces captures d'écran, je ne connais pas d'autre moyen de montrer que je l'ai ajouté (je ne suis pas habitué à Eclipse).

6
Marek

J'ai résolu ceci par essais et erreurs. Ce que cela a fait pour moi a été de supprimer un fichier application.properties du formulaire de référence de pilote. Ainsi, mon fichier application.properties ressemble à ceci, et l'erreur a immédiatement disparu:

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

Je pense que cela a à voir avec la probabilité que vous ayez besoin de ce pilote dans Tomcat intégré et non dans le code de l'application elle-même.

6
Bostone

Je sais que mon cas est spécial, mais je devrais laisser les autres savoir ce que j'ai trouvé.

Dans mon cas, - J'avais installé Gradle avec Brew, la version de Gradle est 2.1 (même maintenant) - Problème: com.mysql.jdbc.La classe du conducteur n'a pas été trouvée

J'ai essayé de nombreuses manières, mais j'ai finalement résolu le problème: Upgrade Gradle (3.3, par exemple.)

  • mise à niveau
  • gradle init à nouveau (supprimez build.gradle et settings.gradle)
  • faire copier tout de l'ancienne construction/paramètres à la nouvelle construction/paramètres

et cela a fonctionné.

0
user7399910

ajoutez ceci à votre pom.xml:

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

puis vérifiez application.properties

0
huster

@EnableAutoConfiguration s'assurera que les beans appropriés sont chargés, ici le pilote sera chargé par Spring Boot. Voir documentation

Dans votre cas, je ne vois pas que le fichier jar du pilote MySQL n'est pas inclus dans le chemin d'accès aux classes et que, par conséquent, Spring ne parvient pas à trouver la classe Driver. Recherchez "ClasspathLoggingApplicationListener" dans le journal pour voir que tous les fichiers JAR sont inclus pour exécuter l'application.

0
kamoor