h2 관련 오류 모음

개발노트/오류해결

2022. 6. 4. 19:16


접속(Connect)하려 했더니

"Whitelabel Error Page"가 나오고, 403 에러(error)를 낸다면?

 

→ 보안설정과 관련된 메서드를 오버라이딩해준다.

이는 WebSecurityConfigurerAdapter 클래스의 configure 메서드를 말한다.

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    //h2-console의 접근권한 부여하기
    @Override
    protected void configure(HttpSecurity http) throws Exception {
    	//h2-console 뒤의 모든 경로에 대한 접근 허가
        http.authorizeRequests().antMatchers("/h2-console/**").permitAll();
        http.csrf().disable();
        http.headers().frameOptions().disable();
    }
}

 


 

데이터베이스를 생성하려는데,

"not found" 에러가 발생한 경우

 

에러메시지:

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

 

최신 h2 버전에서는 데이터베이스를 미리 생성하는 것을 방지하기 때문이다.

따라서 복수의 방법이 존재한다.

 

→ h2 database를 1.3.x의 버전으로 재설치 한다.

 

→ 앱 설정파일(application.properties나 yml)에 가서

다음 설정을 추가해준다.(여기서는 yml)

spring:
  datasource:
    url: jdbc:h2:mem:testdb (예시)
  h2:
    console:
      enabled: true