Monday, April 11, 2022

Create MySql connection with Spring Boot and JPA

 create a project with spring Initializer :



<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

If you add JPA and MySql int to your project, you can simply add spring JPA and MySQL driver dependencies into pom.xml 


The first thing is to create an application property with MySQL :

spring.datasource.url=jdbc:mysql://localhost:3306/sms?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
spring.datasource.username=root
spring.datasource.password=tstc123

#Hibernate
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect

#Hibernate auto ddl
spring.jpa.hibernate.ddl-auto=update

logging.level.org.hibernate.SQL=DEBUG 

No comments:

Post a Comment

Feign Client Using Spring Boot | @EnableFeignClient | @FeignClient | FeignClient Spring Cloud

This is the video where I learnt Feign client, short and simple explanation. 1. Add dependency  <dependency> <groupId> ...