无法使用RepositoryRestResource添加http拦截器

时间:2019-06-12 01:09:55

标签: java spring-boot interceptor

我尝试使用WebMvcConfigurer在RepositoryRestResource调用上添加http拦截器,但除我的存储库请求之外,所有收到的请求都被调用拦截器


// CLASS: SPRING BOOT APPLICATION
@SpringBootApplication
@EnableWebMvc
public class myApplication {

    public static void main(String[] args) {
        SpringApplication.run(myApplication .class, args);
    }

}

// CLASS: GCP DATA STORE REPOSITORY
@RepositoryRestResource
public interface PassportRepository extends DatastoreRepository<Passport, String> {

}

// CLASS: MVC CONFIG
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    MyInterceptor myInterceptor ;

    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(myInterceptor).addPathPatterns("/**");
    }
}


// CLASS: INTERCEPTOR
@Component
public class MyInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler)  {
        System.out.println("TEST!");
        return true;
    }

}

当我打电话给http://localhost:8080/passports/1234时,我希望拦截器记录“ TEST”,但没有。

当我打电话给http://localhost:8080/anythingelse时。我的拦截器记录了测试

我做错了什么?

0 个答案:

没有答案