Spring

h2-console "mem:testdb" not found 문제 해결하는 한가지 방법

kimc 2022. 4. 9. 06:11
반응형

 

이번 글을 통해 배워 갈 내용

  1. H2 in memory db 연결 시 문제 해결법

아침 4시에 일어나서 경건한 마음으로 코딩 공부를 하면서

Eureka Discovery Server에 Gateway와 Client Server를 붙이는 연습을 하고 있었는데

 

 

Client Server에 in memory Data를 붙이던 도중

아래와 같은 에러가 발생했습니다.

 

Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments)

 

 

단순하게 로컬 환경에서 테스트하고자 하였기 때문에

아래와 같이 spring boot application.properties 파일에 추가해주었고

(Yaml은 Yaml 형식에 맞춰서 추가해주시면 됩니다)

# 코드
#enable h2 console
spring.h2.console.enabled=true
spring.h2.console.settings.web-allow-others=true
spring.datasource.generate-unique-name = false 
spring.h2.console.path=/h2-console
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
# 설명

#h2 console 활성화
spring.h2.console.enabled=true 

# 원격접속 허용
spring.h2.console.settings.web-allow-others=true

# 유일한 이름 생성 여부
spring.datasource.generate-unique-name = false 

# h2 console 경로
spring.h2.console.path=/h2-console

# h2 url 경로
spring.datasource.url=jdbc:h2:mem:testdb

# class 명칭
spring.datasource.driverClassName=org.h2.Driver

 

jpa dependency를 Pom 파일에 h2 depency 아래에 추가해주었습니다.

(Gradle은 Gradle 형식에 맞춰서 추가해주시면 됩니다)

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

 

이렇게 해주고 해당되는 서버들을 재실행해주면~

성공하였습니다.

 

 

 

 

 


참조 및 인용

https://stackoverflow.com/questions/56209686/h2-database-not-found-error-90146-h2-database-is-not-created-on -start

 

H2 Database not found error: 90146. H2 database is not created on start

Just created a simple spring-boot project from the spring initializer. I went to add a local h2 db for testing and am unable to login. Seems that it cannot create the test db when starting up but c...

stackoverflow.com

 

 


블로그 추천 포스트

https://codemasterkimc.tistory.com/50

 

300년차 개발자의 좋은 코드 5계명 (Clean Code)

이번 글을 통해 배워갈 내용  좋은 코드(Clean Code)를 작성하기 위해 개발자로서 생각해볼 5가지 요소를 알아보겠습니다. 개요 좋은 코드란 무엇일까요? 저는 자원이 한정적인 컴퓨터 세상에서 좋

codemasterkimc.tistory.com

 

 

오늘도 즐거운 코딩 하시길 바랍니다 ~ :)

 


 

반응형