I have a problem about defining hibernate dialect in my Spring Cloud example.
I got this error when I run user service, report service and advertisement service.
How can I fix it?
java.lang.ClassCastException: class org.hibernate.dialect.MySQL8Dialect cannot be cast to class java.sql.Driver (org.hibernate.dialect.MySQL8Dialect is in unnamed module of loader org.
springframework.boot.loader.LaunchedURLClassLoader @2096442d; java.sql.Driver is in module java.sql of loader 'platform')
Here is the properties file of user service.
#spring.datasource.url=jdbc:mysql://localhost:3306/springbootuser?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Turkey
spring.datasource.url=jdbc:mysql://database:3366/springbootuser?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Turkey
spring.datasource.username=springmicroserviceuser
spring.datasource.password=111111
# Define hibernate settings (JPA / Hibernate properties)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
server.port=9000
spring.application.name=user-service
#eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.client.serviceUrl.defaultZone=http://eurekaserver:8761/eureka
keycloak.realm=master
#keycloak.auth-server-url=http://localhost:8181
keycloak.auth-server-url=http://keycloak:8181
keycloak.ssl-required=external
keycloak.resource=spring-boot-microservice-keycloak
keycloak.bearer-only=true
keycloak.public-client=true
Here is the properties file of report service.
#spring.datasource.url=jdbc:mysql://localhost:3306/springbootreport?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Turkey
spring.datasource.url=jdbc:mysql://database:3366/springbootreport?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Turkey
spring.datasource.username=springmicroserviceuser
spring.datasource.password=111111
# Define hibernate settings (JPA / Hibernate properties)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
server.port=9003
spring.application.name=report-service
#eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.client.serviceUrl.defaultZone=http://eurekaserver:8761/eureka
keycloak.realm=master
#keycloak.auth-server-url=http://localhost:8181
keycloak.auth-server-url=http://keycloak:8181
keycloak.ssl-required=external
keycloak.resource=spring-boot-microservice-keycloak
keycloak.bearer-only=true
keycloak.public-client=true
queue.name=queue-advertisement
spring.rabbitmq.template.exchange=adv-exchange
spring.rabbitmq.template.routing-key=adv-routing
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=quest
spring.rabbitmq.password=quest
spring.main.allow-bean-definition-overriding=true
Here is the properties file of advertisement service.
#spring.datasource.url=jdbc:mysql://localhost:3306/springbootadvertisement?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Turkey
spring.datasource.url=jdbc:mysql://database:3366/springbootadvertisement?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Turkey
spring.datasource.username=springmicroserviceuser
spring.datasource.password=111111
# Define hibernate settings (JPA / Hibernate properties)
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
server.port=9001
spring.application.name=advertisement-service
#eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka
eureka.client.serviceUrl.defaultZone=http://eurekaserver:8761/eureka
keycloak.realm=master
#keycloak.auth-server-url=http://localhost:8181
keycloak.auth-server-url=http://keycloak:8181
keycloak.ssl-required=external
keycloak.resource=spring-boot-microservice-keycloak
keycloak.bearer-only=true
keycloak.public-client=true
# Messaging Properties
queue.name=queue-advertisement
spring.rabbitmq.template.exchange=adv-exchange
spring.rabbitmq.template.routing-key=adv-routing
spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=rabbitmq
spring.rabbitmq.password=123456
spring.main.allow-bean-definition-overriding=true
Here is my docker-compose fiile
services:
database:
container_name: mysql-database
image: 'mysql:latest'
ports:
- "3366:3306"
restart: always
environment:
#MYSQL_DATABASE: "springbootuser"
MYSQL_USER: "springmicroserviceuser"
MYSQL_PASSWORD: "111111"
MYSQL_ROOT_PASSWORD: "111111"
volumes:
- db-data:/var/lib/mysql
networks:
- backend
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
keycloak:
image: quay.io/keycloak/keycloak:18.0.2
environment:
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=admin
ports:
- "8181:8080"
networks:
- backend
command:
- start-dev
rabbitmq:
image: "rabbitmq:3-management"
container_name: "rmq3"
environment:
RABBITMQ_DEFAULT_USER: "rabbitmq"
RABBITMQ_DEFAULT_PASS: "123456"
ports:
- "5672:5672"
- "15672:15672"
configserver:
image: configserver
container_name: configServer
build:
context: ./configserver
dockerfile: Dockerfile
environment:
CONFIGSERVER_URI: "http://configserver:9191"
CONFIGSERVER_PORT: "9191"
ports:
- "9191:9191"
networks:
- backend
eurekaserver:
image: eurekaserver
ports:
- "8761:8761"
build:
context: ./discoveryserver
dockerfile: Dockerfile
environment:
CONFIGSERVER_URI: "http://configserver:9191"
CONFIGSERVER_PORT: "9191"
EUREKASERVER_URI: "http://eurekaserver:8761/eureka/"
EUREKASERVER_PORT: "8761"
depends_on:
configserver:
condition: service_started
networks:
- backend
gatewayserver:
image: gatewayserver
ports:
- "8600:8600"
build:
context: ./api-gateway
dockerfile: Dockerfile
environment:
PROFILE: "default"
SERVER_PORT: "8600"
CONFIGSERVER_URI: "http://configserver:9191"
EUREKASERVER_URI: "http://eurekaserver:8761/eureka/"
EUREKASERVER_PORT: "8761"
CONFIGSERVER_PORT: "9191"
depends_on:
configserver:
condition: service_started
eurekaserver:
condition: service_started
networks:
- backend
userservice:
image: user-service
build:
context: ./user-service
dockerfile: Dockerfile
environment:
SERVER_PORT: "9000"
CONFIGSERVER_URI: "http://configserver:9191"
CONFIGSERVER_PORT: "9191"
EUREKASERVER_URI: "http://eurekaserver:8761/eureka/"
EUREKASERVER_PORT: "8761"
SPRING_DATASOURCE_URL: "jdbc:mysql://database:3366/springbootuser?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Turkey"
SPRING_DATASOURCE_DRIVER_CLASS_NAME: "org.hibernate.dialect.MySQL8Dialect"
SPRING_DATASOURCE_USERNAME: "springmicroserviceuser"
SPRING_DATASOURCE_PASSWORD: "111111"
SPRING_JPA_HIBERNATE_DDL_AUTO: "update"
depends_on:
database:
condition: service_healthy
configserver:
condition: service_started
ports:
- "9000:9000"
networks:
- backend
managementservice:
image: management-service
build:
context: ./management-service
dockerfile: Dockerfile
environment:
SERVER_PORT: "9002"
CONFIGSERVER_URI: "http://configserver:9191"
CONFIGSERVER_PORT: "9191"
EUREKASERVER_URI: "http://eurekaserver:8761/eureka/"
EUREKASERVER_PORT: "8761"
depends_on:
configserver:
condition: service_started
advertisementservice:
condition: service_started
reportservice:
condition: service_started
ports:
- "9002:9002"
networks:
- backend
advertisementservice:
image: advertisement-service
build:
context: ./advertisement-service
dockerfile: Dockerfile
environment:
SERVER_PORT: "9001"
CONFIGSERVER_URI: "http://configserver:9191"
CONFIGSERVER_PORT: "9191"
EUREKASERVER_URI: "http://eurekaserver:8761/eureka/"
EUREKASERVER_PORT: "8761"
SPRING_DATASOURCE_URL: "jdbc:mysql://database:3366/springbootadvertisement?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Turkey"
SPRING_DATASOURCE_DRIVER_CLASS_NAME: "org.hibernate.dialect.MySQL8Dialect"
SPRING_DATASOURCE_USERNAME: "springmicroserviceuser"
SPRING_DATASOURCE_PASSWORD: "111111"
SPRING_JPA_HIBERNATE_DDL_AUTO: "update"
depends_on:
database:
condition: service_healthy
configserver:
condition: service_started
ports:
- "9001:9001"
networks:
- backend
reportservice:
image: report-service
build:
context: ./report-service
dockerfile: Dockerfile
environment:
SERVER_PORT: "9003"
CONFIGSERVER_URI: "http://configserver:9191"
CONFIGSERVER_PORT: "9191"
EUREKASERVER_URI: "http://eurekaserver:8761/eureka/"
EUREKASERVER_PORT: "8761"
SPRING_DATASOURCE_URL: "jdbc:mysql://database:3366/springbootreport?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Turkey"
SPRING_DATASOURCE_DRIVER_CLASS_NAME: "org.hibernate.dialect.MySQL8Dialect"
SPRING_DATASOURCE_USERNAME: "springmicroserviceuser"
SPRING_DATASOURCE_PASSWORD: "111111"
SPRING_JPA_HIBERNATE_DDL_AUTO: "update"
depends_on:
database:
condition: service_healthy
configserver:
condition: service_started
ports:
- "9003:9003"
networks:
- backend
networks:
backend:
driver: bridge
volumes:
db-data:
Here is my project link : Link