Not Able to Connect JDBC-Hikari To my Micronaut App

4.3k Views Asked by At

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
2

There are 2 best solutions below

10
On BEST ANSWER

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'
0
On

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}