티스토리 뷰

에러 메세지

Cannot resolve method 'antMatchers' in 'ExpressionInterceptUrlRegistry’
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
    http
            .csrf().disable()
            .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
            .and()
            .cors().configurationSource(corsConfigurationSource()).and()
            .authorizeRequests()
            .antMatchers("/api/v1/users/*").permitAll()
            .antMatchers("/api/v1/login").permitAll()
            .antMatchers("/api/v1/profile").permitAll()
            .anyRequest().authenticated()
            .and()
            .httpBasic().disable()
            .formLogin().disable()
            .apply(new JwtConfigurer(jwtTokenProvider));

    http.exceptionHandling()
            .authenticationEntryPoint(new CustomAuthenticationEntryPoint())
            .accessDeniedHandler(new CustomAccessDeniedHandler());

    return http.build();
}

antMatchers 에서 메소드를 찾을 수 없다는 에러 발생 !

 

 

원인

HttpSecurity 객체에서 authorizeRequests() 메소드를 호출한 후 반환된 ExpressionInterceptUrlRegistry 객체에서

authorizeRequests() 메소드를 찾을 수 없을 때 발생한다.

 

ExpressionInterceptUrlRegistry 클래스에서 antMatchers() 메소드를 제공하는데,
ExpressionInterceptUrlRegistry 클래스는 spring-security-config 라이브러리에 포함되어 있어서 라이브러리 등록이 안되어 있으면 antMatchers() 메소드를 사용할 수 없다는 에러가 발생한다.

 

 

해결방법

spring-security-config 의존성 설정이 되어있는지 확인해봐야한다.

세상에나 안 되어 있었다! ㅎ 의존성을 추가해줘야 한다.

 

 

Gradle dependencies 에 spring-security-config Library 추가

implementation 'org.springframework.security:spring-security-config:5.6.0'

 

 

 

 

반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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 31
글 보관함