Spring
[SpringBoot] h2-console 웹 접근안될 때 해결 방법
자기개발자 유자
2021. 3. 8. 21:19
728x90
반응형
Springboot에서 H2를 적용하고, 웹 콘솔 사용여부 true 처리하였는데 웹 접근이 안되는 상황을 겪었다.
찾아보니 원인은 아주 간단하지만 놓치기 쉬운 부분이었다.
application.properties 의 h2 적용 상태
# 상단 생략
spring.datasource.url=jdbc:h2:~/test;AUTO_SERVER=TRUE
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.h2.console.enabled=true
spring.h2.console.settings.web-allow-others=true
spring.h2.console.path=/h2-console
웹에서 'localhost:8080/h2-console' 진입 시도 -> Error Page!!
해결 방법
-
Spring Security 사용하는 경우 permitAll 경로로 추가해주어야 한다.
SecurityConfig.java
@Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override public void configure(WebSecurity web) throws Exception { web.ignoring().antMatchers("/h2-console/**"); // --> 추가 } @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/", "/h2-console/**", "/events", "/events/*").permitAll() // --> 추가 .anyRequest().authenticated() .and() .httpBasic().disable() .csrf().disable(); } }
h2-console 정상 접근 ^-^
SpringSecurity는 URL 접근에 항상 제한을 건다.😂
API를 추가할 때나 이렇게 브라우저 접근이 추가로 필요할 때 항상 SpringSecurity를 적용했다는 것을 잊지 말자!
왜안될까? 의심될 땐 SecurityConfig를 살펴보자.😎
728x90
반응형