Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 347
vamsi Avatar asked Nov 20 '22 19:11

vamsi


1 Answers

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

like image 65
Nick Lin Avatar answered Jun 29 '23 01:06

Nick Lin