728x90
에러
localhost에서 연결을 거부했습니다.
문제상황
: Spring Sequrity적용 후 h2에 접속하면 이런 화면이 뜬다


해결방법
: Spring Sequrity Configure 클래스에서 다음의 설정을 해줘야 한다.
@Configuration
public class SecurityConfiguration {
private final JwtTokenizer jwtTokenizer;
private final CustomAuthorityUtils authorityUtils;
public SecurityConfiguration(JwtTokenizer jwtTokenizer, CustomAuthorityUtils authorityUtils) {
this.jwtTokenizer = jwtTokenizer;
this.authorityUtils = authorityUtils;
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.headers().frameOptions().sameOrigin() // <<= h2 허용해주는 부분
.and()
.csrf().disable()
.cors(withDefaults())
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.formLogin().disable()
.httpBasic().disable()
.exceptionHandling()
.authenticationEntryPoint(new AccountAuthenticationEntryPoint())
.accessDeniedHandler(new AccountAccessDeniedHandler())
.and()
.apply(new CustomFilterConfigurer())
.and()
.authorizeHttpRequests(authorize -> authorize
.anyRequest().permitAll()
);
return http.build();
}
참고용 h2 application.yml 파일 (위의 코드 적용시 사용한 yml)
spring:
h2:
console:
enabled: true
path: /h2
datasource:
url: jdbc:h2:mem:test
jpa:
hibernate:
ddl-auto: create # (1) 스키마 자동 생성
show-sql: true # (2) SQL 쿼리 출력
properties:
hibernate:
format_sql: true # (3) SQL pretty print
sql:
init:
data-locations: classpath*:db/h2/data.sql
logging:
level:
org:
springframework:
orm:
jpa: DEBUG
server:
servlet:
encoding:
force-response: true728x90
'Java & Spring > Error' 카테고리의 다른 글
| [SpringBoot] failed to load applicationcontext (0) | 2022.11.02 |
|---|---|
| [SpringBoot] jpasystemexception 예외 (0) | 2022.11.02 |
| [IntelliJ] yml 파일 인식오류 (프로파일 인식 안됨) (0) | 2022.10.31 |
| [IntelliJ] Git clone한 프로젝트 열 때, 루트 경로 및 JDK 인식 오류 (0) | 2022.10.28 |
| [SpringBoot] not enough variable values available to expand 에러 (0) | 2022.10.28 |