This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from microservices-demo/fix/http-middleware
Another way to add a http middleware that works with spring boot.
- Loading branch information
Showing
1 changed file
with
5 additions
and
11 deletions.
There are no files selected for viewing
16 changes: 5 additions & 11 deletions
16
src/main/java/works/weave/socks/orders/config/WebMvcConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
package works.weave.socks.orders.config; | ||
|
||
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.orders.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); | ||
} | ||
} |