본문 바로가기
🍃SpringFrameworks/SpringDataJPA

[JPA] JPA - MySQL 연동

by inbeom 2023. 9. 10.
728x90

 💡 JPA와 MySQL을 연동하여 사용해보자!

1. 우측 상단 메뉴바의 Database → ‘+’버튼 → DataSource → MySQL → root(pw) 입력하고 OK

 

2. application.yml 파일에 정의

spring:
 h2:
  console:
	enabled: true
 jpa:
	show-sql: true
	properties:
          hibernate:
		format_sql: true
	generate-ddl: true
	hibernate:
	  ddl-auto: create-drop
 datasource:
	url: jdbc:mysql://localhost
	username: root
	password: 
 sql:
  init:
    mode: always

 

3. build.gradle 파일에 코드 추가

implementation 'org.springframework.boot:spring-boot-starter-data-jpa’

implementation 'mysql:mysql-connector-java:8.0.16’

 

4. ApplicationTest파일에서 contextLoads() 메서드 실행하여 연결 테스트

 

 

728x90