In this article we are going to discuss about ,how to connect to MySQL database using JPA and Spring Boot.
As we know JPA is an ORM extension to ORM tool, used to store data in the form of Objects.
How To Configure JPA and MySQL in Spring Boot
We need to follow below steps for doing configuration of JPA and MySQL in Spring boot.
1.First , We need to add JPA dependency, Spring Boot web, MySQL driver starter in the POM.XML file in the dependencies section.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
- After that, we need to add below listed details in the application.properties file for doing configuration.
server.port=1200
spring.datasource.username=root
spring.datasource.password=*****
spring.datasource.url=jdbc:mysql://localhost/****
spring.jpa.hibernate.ddl-auto=update
- At last, we need to run the application and our application will be ready to connect to MySQL database.
Thank you
Top comments (0)