H2 Database

http://www.h2database.com/html/main.html

  • Pure Java
  • Memory Mode
  • Encrypted Database
  • ODBC Driver
  • Full text Search
  • Multi Version Concurrency

Gradle Setting

edit build.gradle

dependencies {
    runtime('com.h2database:h2')
}

runtime 프로젝트를 실행할 때 필요한 의존 라이브러리들. 기본적으로 compile을 모두 포함한다.
compile 프로젝트를 컴파일할 때 필요한 의존 라이브러리들

Spring Security Setting

edit WebSecurityConfiguration.java

@Override
public void configure(WebSecurity web) throws Exception {
	web
		.ignoring()
		.antMatchers("/h2-console/**")
}

H2 Setting

edit application.yml

spring:
  profiles: h2database
  jpa:
    generate-ddl: true
    hibernate:
      ddl-auto: create-drop
  h2:
    console:
      enabled: true
      path: /h2-console
  datasource:
#    url: jdbc:h2:mem:mcdonald
#    initialize: true
#    schema: classpath:database/sql/greeting.sql,classpath:database/sql/ddl_*.sql
#    data: classpath:database/sql/dml_*.sql
    
    type: org.apache.tomcat.jdbc.pool.DataSource
    driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
    url: jdbc:log4jdbc:h2:mem:mcdonald
    username: **
    password: ****
    initialize: true
    schema: classpath:database/sql/greeting.sql,classpath:database/sql/ddl_*.sql
    data: classpath:database/sql/dml_*.sql

H2 Console 접속

  • application.yml 에서 지정한 경로로 접근한다.

http://localhost:8081/manager/h2-console

  • 지정한 정보를 입력후 [Connect]
  • JDBC URL : jdbc:h2:mem:mcdonald
  • User Name: **
  • Password: ****