Commit 1ef22f59 authored by Phil Winder's avatar Phil Winder Committed by GitHub

Merge pull request #28 from microservices-demo/fix/http-middleware

Another way to add a http middleware that works with spring boot.
parents bade28b7 abf20112
package works.weave.socks.cart.configuration; package works.weave.socks.cart.configuration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.handler.MappedInterceptor;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import works.weave.socks.cart.middleware.HTTPMonitoringInterceptor; import works.weave.socks.cart.middleware.HTTPMonitoringInterceptor;
@Configuration @Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter { public class WebMvcConfig {
@Autowired
private HTTPMonitoringInterceptor httpMonitoringInterceptor;
@Bean @Bean
HTTPMonitoringInterceptor httpMonitoringInterceptor() { HTTPMonitoringInterceptor httpMonitoringInterceptor() {
return new HTTPMonitoringInterceptor(); return new HTTPMonitoringInterceptor();
} }
@Override @Bean
public void addInterceptors(InterceptorRegistry registry) { public MappedInterceptor myMappedInterceptor(HTTPMonitoringInterceptor interceptor) {
registry.addInterceptor(httpMonitoringInterceptor) return new MappedInterceptor(new String[]{"/**"}, interceptor);
.addPathPatterns("/**");
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment