Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot load driver class: com.mysql.jdbc.Driver with Gradle and Spring Boot

My problem is the following. I'm learning how to use JDBC, Gradle and Spring framework (I'm new to those subjects). I've been trying to implement the following example with one difference, MySQL database instead of PostgreSQL.

Like I specified in the title, my application ends with following error Cannot load driver class: com.mysql.jdbc.Driver (stack trace at the end of the post).

Of course I've been googling and reading before posting this question and I found that com.mysql.jdbc.Driver should be loaded either using loader in program or it also can be done withing Gradle build script.

My questions are the following:

  1. Why authors example works without loader (either in program either in build script)
  2. If loader is absolutely necessarily, could you explain briefly how to implement it?

My modified build.gradle file:

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

My application.properties file:

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

Stack trace (not full):

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

Thank you in advance for any advices, exploanations, shared examples et cetera! Cheers!

Edit #1

As Mr. Kamoor kindly suggested it may be problem of lack of local *jar file. I suspected that Gradle will download it automatically from repository, in case if it wouldn't I added it manually (I work on STS). Here we can see that mysql-connector-java jar is there.

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

I'm sorry for those screen shoots, I just don't know other way to show that I added it (I'm not used to Eclipse).

like image 778
Marek Avatar asked Jan 03 '15 19:01

Marek


2 Answers

I solved this by trial and error. What did it for me was to remove a driver reference form application.properties file. So my application.properties file looks like this, and the error immediately went away:

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

I think it has to do with the probability that you need that driver in the embedded Tomcat and not in the application code itself

like image 154
Bostone Avatar answered Oct 06 '22 21:10

Bostone


I know my case is special, but I should let others know what I have found.

In my case, - I had installed gradle with brew, gradle version is 2.1 (even now) - Problem: com.mysql.jdbc.Driver class not found

I tried many ways but finally I solved the problem: Upgrade Gradle (3.3, for example.)

  • upgrade gradle
  • gradle init again (remove build.gradle and settings.gradle)
  • make copy everything from old build/settings to new build/settings

and it worked.

like image 23
user7399910 Avatar answered Oct 06 '22 21:10

user7399910