From abf2011255c22339a71b98233f0e79627dc6f54f Mon Sep 17 00:00:00 2001 From: Phil Winder Date: Wed, 15 Mar 2017 09:26:46 +0000 Subject: [PATCH] Another way to add a http middleware that works with spring boot. --- .../socks/cart/configuration/WebMvcConfig.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/main/java/works/weave/socks/cart/configuration/WebMvcConfig.java b/src/main/java/works/weave/socks/cart/configuration/WebMvcConfig.java index a6e7eded8..7eac966a0 100644 --- a/src/main/java/works/weave/socks/cart/configuration/WebMvcConfig.java +++ b/src/main/java/works/weave/socks/cart/configuration/WebMvcConfig.java @@ -1,25 +1,19 @@ package works.weave.socks.cart.configuration; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.handler.MappedInterceptor; import works.weave.socks.cart.middleware.HTTPMonitoringInterceptor; @Configuration -public class WebMvcConfig extends WebMvcConfigurerAdapter { - @Autowired - private HTTPMonitoringInterceptor httpMonitoringInterceptor; - +public class WebMvcConfig { @Bean HTTPMonitoringInterceptor httpMonitoringInterceptor() { return new HTTPMonitoringInterceptor(); } - @Override - public void addInterceptors(InterceptorRegistry registry) { - registry.addInterceptor(httpMonitoringInterceptor) - .addPathPatterns("/**"); + @Bean + public MappedInterceptor myMappedInterceptor(HTTPMonitoringInterceptor interceptor) { + return new MappedInterceptor(new String[]{"/**"}, interceptor); } }