๐Ÿ“‚ JAVA/Spring

[SpringBoot] H2 Database ์—ฐ๊ฒฐํ•˜๊ธฐ

dhyuck 2022. 3. 13. 23:26
๋ฐ˜์‘ํ˜•
  • H2๋Š” ์ธ๋ฉ”๋ชจ๋ฆฌ ๊ธฐ๋ฐ˜์˜ JAVA ๋ฐ์ดํ„ฐ ๋ฒ ์ด์Šค๋กœ, ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•˜๋Š” ๋‹จ๊ฒŒ์—์„œ ๋งŽ์ด ์‚ฌ์šฉ์ด ๋ฉ๋‹ˆ๋‹ค.

    ์•„๋ž˜๋Š” H2 ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ํ™œ์„ฑํ™” ํ•˜๊ณ  SpringBoot์™€ H2์™€ ์—ฐ๊ฒฐํ•˜๋Š” ๋ฐฉ๋ฒ•์ž…๋‹ˆ๋‹ค.

  • ํ™˜๊ฒฝ

    • Gradle 7.3.3
    • Spring Boot 2.6.4
  • build.gradle

      dependencies {
          runtimeOnly 'com.h2database:h2'
      }
  • application.yml

      spring:
        h2:
          console.enabled: true
    
        datasource:
          url: jdbc:h2:mem:testdb
          username: sa
          password:
          driver-class-name: org.h2.Driver
  • h2 ์ ‘์†๋ฐฉ๋ฒ•

    ์›น ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์ด์šฉํ•˜์—ฌ url:{ํฌํŠธ}/h2-conosle๋กœ ์ ‘์†ํ•˜๋ฉด H2๋กœ ์ ‘์† ํ•  ์ˆ˜์žˆ์Šต๋‹ˆ๋‹ค.

      localhost:8080/h2-console

  • org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database "mem:testdb" not found

    ํ•ด๋‹น ์—๋Ÿฌ๋Š” DB๊ฐ€ ์•„์ง ์ƒ์„ฑ๋˜์ง€ ์•Š์•˜๊ธฐ์— ์ƒ๊ธฐ๋Š” ์—๋Ÿฌ์ด๋‹ค. DB๊ฐ€ ์ƒ์„ฑ๋˜๋ฉด ์ ‘์†์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

๋ฐ˜์‘ํ˜•