I registered my interceptor with the following code
@EnableWebMvc public class WebMvcConfig extends WebMvcConfigurerAdapter { ... @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor( myInterceptor() ); } ... }
Here is the definition of an interceptor
public class MyInterceptorimplements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
However, handler.getClass (). getDeclaredAnnotations () does not return Controller interceptor class level annotations.
I can only get method level annotations that I don't want in this case.
The same interceptor works fine with xml configuration (using Spring 3):
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> <property name="interceptors"> <list> <ref bean="myInterceptor"/> </list> </property> </bean>
Is there a way to get class level information in Spring 4?
According to Spring -mvc interceptor, how can I access the controller controller method? "HandlerInterceptors will give you access to HandlerMethod" using the configuration above. But what is the alternative configuration for getting class level information?
source share