2

Error I am Getting after running sudo ./gradlew run :

Task :run FAILED 12:03:13.440 [main] ERROR com.zaxxer.hikari.HikariConfig - Failed to load driver class com.mysql.jdbc.Driver from HikariConfig class classloader jdk.internal.loader.ClassLoaders$AppClassLoader@3d4eac69 12:03:13.445 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Bean definition [javax.sql.DataSource] could not be loaded: Error instantiating bean of type [javax.sql.DataSource]

How my Application.yml looks like :


micronaut:
  application:
    name: freshdb2

#datasources.default: {}

datasources:
  default:
    url: jdbc:mysql://localhost:3306/mydb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
    username: root
    password: ""
    driverClassName: com.mysql.jdbc.Driver
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
ukdev
  • 25
  • 1
  • 7

2 Answers2

2

You are missing driver, you should add dependency mysql-connector-java, for gradle add:

runtime group: 'mysql', name: 'mysql-connector-java', version: '8.0.13'
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
  • I Didnt Got you! Can you Please Copy paste the Correction ? – ukdev Nov 14 '19 at 07:11
  • @ukdev remove `driverClassName: com.mysql.jdbc.Driver` – Ori Marko Nov 14 '19 at 07:12
  • Now I am Getting this Error > Task :run FAILED 12:49:02.762 [main] ERROR com.zaxxer.hikari.HikariConfig - Failed to load driver class com.mysql.jdbc.Driver from HikariConfig class classloader jdk.internal.loader.ClassLoaders$AppClassLoader@3d4eac69 12:49:02.769 [main] ERROR io.micronaut.runtime.Micronaut - Error starting Micronaut server: Bean definition [javax.sql.DataSource] could not be loaded: Error instantiating bean of type [javax.sql.DataSource] – ukdev Nov 14 '19 at 07:19
  • @ukdev you are probably missing mysql jar in classpath see https://stackoverflow.com/questions/25546417/where-can-i-download-mysql-jdbc-jar-from – Ori Marko Nov 14 '19 at 07:21
  • Man, I checked Everything It is Still not working and giving this Error message: Caused by: io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type [javax.sql.DataSource] Message: Failed to load driver class com.mysql.jdbc.Driver in either of HikariConfig class loader or Thread context classloader Path Taken: DataSource.dataSource([DatasourceConfiguration datasourceConfiguration]) – ukdev Nov 14 '19 at 07:35
  • @ukdev you should have `mysql-connector-java`, e.g. in gradle `runtime group: 'mysql', name: 'mysql-connector-java', version: '8.0.13'` – Ori Marko Nov 14 '19 at 07:40
  • Thank you So much It worked For me. http://makble.com/gradle-example-to-connect-to-mysql-with-jdbc-in-eclipse – ukdev Nov 14 '19 at 09:20
  • @ukdev Great, you can accept the answer if it helped – Ori Marko Nov 14 '19 at 09:22
  • Done. Thanks Again. – ukdev Nov 15 '19 at 06:42
  • As of MySQL 8.0 [the JDBC driver class name has changed](https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-api-changes.html) from `com.mysql.jdbc.Driver` to `com.mysql.cj.jdbc.Driver`. The old class name has been deprecated (but is still present in MySQL Connector/J at least through version 8.0.28). – MikeOnline Apr 20 '22 at 17:44
0

I was also getting the message:

io.micronaut.context.exceptions.BeanInstantiationException: Error instantiating bean of type [javax.sql.DataSource]

I'm not using MySQL, just trying to unpick how to use JPA from Micronaut Data Guide and others using H2.

It turns out I had incorrectly copied the datasource properties into application.yml. The above message is all you get to tell you this.

In my case the back quotes in the following had become something else.

datasources:   
  default:
    url: ${JDBC_URL:`jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE`}
    username: ${JDBC_USER:sa}
    password: ${JDBC_PASSWORD:""}
    driverClassName: ${JDBC_DRIVER:org.h2.Driver}
    dialect: ${JDBC_DIALECT:H2}
Reg Whitton
  • 655
  • 8
  • 9