我有一个spring数据REST应用程序,其中添加了一个用于身份验证和授权的拦截器。
private static final boolean IS_JPA_AVAILABLE = ClassUtils.isPresent("javax.persistence.EntityManager",
RepositoryRestMvcConfiguration.class.getClassLoader());
@Override
public JpaHelper jpaHelper() {
if (IS_JPA_AVAILABLE) {
JpaHelper helper = new JpaHelper();
helper.getInterceptors().add(new MyInterceptor());
return helper;
} else {
return null;
}
}在这个应用程序中,我也没有控制器。其中一些是@RepositoryRestController,另一些是@BasePathAwareController。当请求到达这些控制器时,我想调用拦截器。对于@RepositoryRestController,会调用拦截器,但对于@BasePathAwareController,则会绕过它。如何为两个控制器类调用这个拦截器?
发布于 2015-10-09 14:41:02
这个问题通过添加映射拦截器来解决(谢谢您的输入)。在configuration类中,我添加了下面的映射拦截器。通过这种方式,将对所有传入控制器的请求调用它。
@Bean
public MappedInterceptor myMappedInterceptor() {
return new MappedInterceptor(new String[]{"/**"}, getSecurityInterceptor());
}参考How to add Custom Interceptor in Spring data rest (spring-data-rest-webmvc 2.3.0)
https://stackoverflow.com/questions/32999692
复制相似问题