[spring] DB 연동

2024. 11. 3. 16:01·Server/spring

나는 mysql을 쓴다.

 

 

1. 내가 쓸 스키마를 확인한다.

나는 abcd를 쓸거다.

 

 

2. build.gradle에 mysql관련 있는지 확인

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	compileOnly 'org.projectlombok:lombok'
	runtimeOnly 'com.mysql:mysql-connector-j'	// 여기
	annotationProcessor 'org.projectlombok:lombok'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

 

3. application.yml 파일에 다음과 같이 작성한다.

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:[사용 포트]/[스키마 명]
    username: [ 실제 username ] 
    password: [ 실제 password ]

 

 

내 예시는 이렇다.

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql:localhost:3306/abcd
    username: user 
    password: 123456

 

'Server > spring' 카테고리의 다른 글

[CICD] SpringBoot + Github Action + EC2 배포  (0) 2025.01.05
[spring] jakarta.servlet.ServletException: Handler dispatch failed: java.lang.NoSuchMethodError: 'void org.springframework.web.method.ControllerAdviceBean.<init>(java.lang.Object)' 에러 해결  (0) 2025.01.02
[spring/IntelliJ] error: Attempt to recreate a file for type ~  (0) 2025.01.02
[spring] Cannot resolve method 'assertThat' in 'Assertions'  (0) 2024.11.29
[spring] Dependency requires at least JVM runtime version 17. This build uses a Java 8 JVM  (0) 2024.10.15
'Server/spring' 카테고리의 다른 글
  • [spring] jakarta.servlet.ServletException: Handler dispatch failed: java.lang.NoSuchMethodError: 'void org.springframework.web.method.ControllerAdviceBean.<init>(java.lang.Object)' 에러 해결
  • [spring/IntelliJ] error: Attempt to recreate a file for type ~
  • [spring] Cannot resolve method 'assertThat' in 'Assertions'
  • [spring] Dependency requires at least JVM runtime version 17. This build uses a Java 8 JVM
2월2
2월2
  • 2월2
    서벅돌의 성장일기
    2월2
  • 전체
    오늘
    어제
    • 분류 전체보기 (120)
      • TIL (2)
      • Server (28)
        • spring (7)
        • node.js (16)
        • 기타 (5)
      • App&Web (17)
        • Web (1)
        • Android (16)
        • iOS (0)
      • 공부 (59)
        • 깃&깃허브 (3)
        • 파이썬 (17)
        • 유니티 (4)
        • 자료구조 | 알고리즘 (15)
        • 자바 (3)
        • 운영체제 (8)
        • AI와 데이터 (9)
      • 대외활동 (12)
        • NPC 동아리 (1)
        • UMC 동아리 (11)
      • 대학교 (1)
        • 교직 (1)
      • 기타 (0)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 글 관리
  • 링크

  • 공지사항

    • Notice
  • 인기 글

  • 태그

    자바
    kotlin
    Unity
    mysql
    루아
    C
    Python
    java
    유니티
    안드로이드
    Lua
    Android
    파이썬
    코틀린
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
2월2
[spring] DB 연동
상단으로

티스토리툴바