-
Springboot + H2 Console 사용 설정우아한 테크코스/이것저것 2020. 7. 28. 13:27반응형
H2 Console이란?
- 작은 용량(2M)의 작고 빠른 DB
- JDBC API 지원
- 브라우저 기반 Console 지원
- 인 메모리(In-Memory) 기반 Server 모드와 Embedded 모드 지원
인 메모리(In-Memory) DB
시스템 메모리에 데이터를 저장, 디스크에 저장하는 방식보다 성능이 좋음. 프로그램이나 DB를 종료하면 데이터가 손실(RAM)
따라서, 초기 개발시에 자주 쓰는 듯Springboot에서 H2 Console 사용하도록 설정
application.properties 기본 설정
spring.datasource.url=jdbc:h2:mem:testdb // testdb 스키마에 인 메모리 DB로 동작 spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password= spring.h2.console.enabled=false
H2 Console 사용하도록 변경
spring.h2.console.enabled=true // 나머지는 위와 동일한 설정으로 기본값 셋팅됨
H2 Console 접근
일반 접근
http://localhost:8080/h2-console - Connect
에러 발생 (Mac OS Catalina 버전 H2 권한 관련 실행 문제)
다음과 같이, 내장 H2 Console로 접근을 하려 했는데 에러가 발생함
http://localhost:8080/h2-console/login.do
발생 에러 상세
더보기Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149 (Help) org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] at org.h2.message.DbException.getJdbcSQLException(DbException.java:622) at org.h2.message.DbException.getJdbcSQLException(DbException.java:429) at org.h2.message.DbException.get(DbException.java:205) at org.h2.message.DbException.get(DbException.java:181) at org.h2.engine.Engine.openSession(Engine.java:71) at org.h2.engine.Engine.openSession(Engine.java:192) at org.h2.engine.Engine.createSessionAndValidate(Engine.java:171) at org.h2.engine.Engine.createSession(Engine.java:166) at org.h2.engine.Engine.createSession(Engine.java:29) at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:340) at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:173) at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:152) at org.h2.Driver.connect(Driver.java:69) at org.h2.util.JdbcUtils.getConnection(JdbcUtils.java:309) at org.h2.util.JdbcUtils.getConnection(JdbcUtils.java:289) at org.h2.server.web.WebServer.getConnection(WebServer.java:785) at org.h2.server.web.WebApp.login(WebApp.java:1008) at org.h2.server.web.WebApp.process(WebApp.java:223) at org.h2.server.web.WebApp.processRequest(WebApp.java:173) at org.h2.server.web.WebServlet.doGet(WebServlet.java:129) at org.h2.server.web.WebServlet.doPost(WebServlet.java:166) at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:834)
발생 이유 : Mac OS Catalina 버전 H2 실행 문제
해결 방법 : H2 Embedded 사용이 아닌, H2 Server를 띄워서 Connect 후 다시 Embedded 사용으로 변경
<!-- h2 설치 --> $ brew install h2 <!-- h2 web console running - 주소가 생기는데 해당 주소로 접근할 것 --> $ h2 -web Web Console server running at http://192.168.7.126:8082?key=5ca6f65423f61b9f17b82c4b2f38a4574bb69609c4700ee7198fc3ff72b015a3 (only local connections)
Save Settings : Generic H2 (Server)
JDBC URL : jdbc:h2:~/test
이 후 커넥션을 종료하고, 다시 위의 (http://localhost:8080/h2-console) 접속을 위와 같은 JDBC URL로 설정하면 연결 성공
- JDBC URL을 못찾는 이슈인 것 같음
커넥션 성공
반응형'우아한 테크코스 > 이것저것' 카테고리의 다른 글
Google App 등록하여 OAuth 2.0 클라이언트 ID 받기 (0) 2020.07.30 도메인 구입하기 (with 가비아) (0) 2020.07.30 Springboot + Gradle + Intellij 환경에서 Lombok 적용하기 (0) 2020.07.29 Self-Signed SSL 인증서 생성하기 & Springboot 적용하기 (0) 2020.07.29 Springboot Logging 적용 - logback (0) 2020.07.29