본문 바로가기

Spring Boot

MySql과 스프링부트 DB 연동

 

스프링부트 프로젝트 안에 src 폴더 -> build.gradle 더블클릭

 

dependencies 안에 JPA 넣어주기

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

 

 

src/main/resources -> application.properties 더블클릭

 

아래문구 넣어주고 수정 부분 수정해주기

spring.datasource.dbcp2.driver-class-name=com.mysql.cj.jdbc.Driverm.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/DB명?characterEncoding=utf8
spring.datasource.username=계정명
spring.datasource.password=비밀번호

 

yml 형식으로 작성할 경우

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/DB명?characterEncoding=utf8
    username: 계정명
    password: 비밀번호
    

//JPA 등등 나머지 관련 설정
    jpa:
      hibernate:
        naming:
          implicit-strategy: org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
          physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

 

반응형

'Spring Boot' 카테고리의 다른 글

@Compnent  (0) 2023.10.17
@SpringBootApplication 동작원리  (0) 2023.10.17
세션(session), 쿠키(cookie)  (0) 2023.09.26
Query String / ?name=value&name=value  (0) 2023.09.21
Spring 기본 구조 및 흐름  (0) 2023.09.20