Aşağıdaki kurulumda, TimingInterceptor ve CORSHeaders önleyici,/resources/** URL'leri dışında tüm URL istekleri üzerinde yürütülür. Önleyicileri ResourceHttpRequestHandler tarafından sunulan/kaynaklar/** URL'leri için nasıl çalışırım?Spring MVC Interceptor, kaynak işleyici URL'leri için çalışmaz
@EnableWebMvc //equivalent to mvc:annotation-driven
@Configuration
@PropertySource("classpath:configuration.properties")
public class WebConfig extends WebMvcConfigurerAdapter {
@Inject
private TimingInterceptor timingInterceptor;
@Inject
private CORSHeaders corsHeaders;
// equivalent to mvc:resources
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
// equivalent to mvc:interceptors
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(timingInterceptor).addPathPatterns("/**");
registry.addInterceptor(corsHeaders).addPathPatterns("/**");
}
}
Evet, bence haklısınız. Önerdiğiniz gibi bir MappedInterceptor eklemeyi denedim, ancak yöntem çağrılmıyor ve engelleyici içeriğe eklenmiyor. – tukushan
Bunun için basit bir örnek oluşturdum: https://github.com/spring-projects/spring-framework-issues/tree/master/SPR-10655 - bir göz atabilir misiniz? Muhtemel bir hata ile bir repro projesi ile gelirseniz, http://jira.spring.io adresindeki bir JIRA sorunu açmanız yeterlidir –
@BrianClozel '@ EnableWebMvc' ve' WebMvcConfigurerAdapter' birlikte tavsiye edilebilir kullanıyor? [Belge] (http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc-auto-configuration) aksini belirtiyor. Yoksa bir şey mi özlüyorum? –