排除所有webmvcconfigurer拦截器的路径

时间:2020-01-16 16:41:21

标签: spring spring-boot spring-mvc

如果我使用的是WebMvcConfiguration并注册了一些拦截器, 是否可以在另一个仅装载特定弹簧轮廓的类中向这些拦截器添加一些排除路径?

示例:

public class TestInterceptor implements WebMvcConfigurer {

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

@Configuration
@Profile("DEV")
public class DevProfileSpecific implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //Modify the interceptor created above with some excluded paths
        //or if you could exclude a path from all interceptors
    }
}

或者我必须做类似的事情

@Profile("!DEV")
public class TestInterceptor implements WebMvcConfigurer {

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

@Configuration
@Profile("DEV")
public class DevProfileSpecific implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myinterceptor()).addPathPatterns("....").excludePathPatterns("....");
    }
}

宁愿不做最后一个,因为我基本上已经有必须维护的重复代码

0 个答案:

没有答案