Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

개발자 도전기

[Spring] a bean of type 'org.apache.catalina.filters.CorsFilter' that could not be found. 본문

개발공부/Spring

[Spring] a bean of type 'org.apache.catalina.filters.CorsFilter' that could not be found.

jnnjnn 2024. 6. 11. 12:50

 

문제

 

cors 설정 중 CorsFilter의 빈을 찾을 수 없다는 오류가 발생했다

 

 

원인

 

SecurityConfiguration에서 CorsFilter 의존성을 주입할 때

import org.apache.catalina.filters.CorsFilter;

 

를 그대로 import했는데, 나는 CorsConfig 클래스에 @Configuration 어노테이션을 붙여 CorsFilter를 @Bean으로 등록했기 때문이다

 

 

해결

private final CorsConfig corsConfig;

 

CorsConfig를 의존성 주입받고 corsConfig.corsFilter() 형태로 사용했다

 

.addFilter(corsConfig.corsFilter())