'Spring Boot in Docker throwing an exception 'hibernate.dialect' not set

I am using spring boot to develop an app and I am using mysql as database.I have the below configuration in application.properties.

server.port=8090
spring.datasource.url=jdbc:mysql://mysql:3306/sampleDB
spring.datasource.username=root
spring.datasource.password=
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.show_sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.temp.use_jdbc_metadata_defaults=false
logging.file=employee.log
spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1

I have the respective DB in my local and it is working in my local. But as soon as I create a docker image and link to my mysql docker container it is throwing the below exception.

org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set

The container is not even building even for me to look into it.

sudo docker run --name bootApp -d  --link mysql:mysql  springio/employeesecurity

where springio/employeesecurity is my springBoot docker name and mysql is my msql container.



Solution 1:[1]

In my case, the reason of the issue was that Spring Boot couldn't get the application.properties, so I added --spring.config.location to Dockerfile to resolve it.

Like this,

FROM openjdk:8-jdk
COPY ./source/*.jar /Folder/spring.jar
WORKDIR /Folder
ENTRYPOINT ["java","-jar","spring.jar","--spring.config.location=/opt/application.properties"]

In addition, I also added spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect to application.properties

Solution 2:[2]

Probably your error is caused by not being able to connect to the db (deeper in your stack)

Have you tried not specifying the port in your connection string:

spring.datasource.url=jdbc:mysql://mysql:3306/sampleDB

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Nick Lin
Solution 2 Ali Dufour