今天用springboot写了一个注解拦截器,一直不生效,网上各种方式我都尝试过了,都不起作用,找了好久总算知道是什么原因了
我的annotation:
@Inherited
@Target({
ElementType.TYPE, ElementType.METHOD
})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface SignVerify {
}
我的intercept:
@Component
public class SodaJsSignInterceptor extends HandlerInterceptorAdapter {
private static final MinaSyncConfiguration config = ZKConfigurationFactory.getConfig(MinaSyncConfiguration.class);
private static final String SIGN_PARAM_NAME = "sign";
private static final Logger LOGGER = LoggerFactory.getLogger(DevController.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
HandlerMethod handlerMethod = (HandlerMethod) handler;
Method method = handlerMethod.getMethod();
SignVerify signVerify = method.getAnnotation(SignVerify.class);
if (signVerify == null) {
return true;
}
return false;
}
}
我的config,问题就是出在config上面:
@Configuration
public class SodaJsSignConfig extends WebMvcConfigurationSupport {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new SodaJsSignInterceptor()).addPathPatterns("/**");
super.addInterceptors(registry);
}
}
到这里所以操作都没有问题,该加的注解我也都加了,最后我发现我有两个拦截器,所以我写了两个config
当我把两个config的内容写到一个config里面以后,拦截器就生效了。。。。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)