Я прочитал эту статью, в нем говорится, что бобы с сопоставлением не будут работать в простой весне, но он помогает мне вызвать перехватчик здесь. Хотя я думаю, что сейчас я использую простую пружину.
Код: Выделить всё
@Configuration
@EnableWebMvc
public class InterceptorConfig implements WebMvcConfigurer {
private final LoginAnnotationInterceptor loginAnnotationInterceptor;
public InterceptorConfig(LoginAnnotationInterceptor loginAnnotationInterceptor) {
this.loginAnnotationInterceptor = loginAnnotationInterceptor;
}
// the interceptor added here cannot be invoked
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(loginAnnotationInterceptor);
}
// the interceptor added here is able to be invoked
@Bean
public MappedInterceptor loginAnnotationInterceptorBean()
{
return new MappedInterceptor(null, loginAnnotationInterceptor);
}
}
< /dode>
loginannotationIntereptor: < /p>
@Component
public class LoginAnnotationInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
System.out.println("It's an interceptor!");
// some logic...
return true;
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... ot-working