Skip to content

Commit

Permalink
[#488]support invocation context in requests. fix bean lifecycle prob…
Browse files Browse the repository at this point in the history
…lem (#695)
  • Loading branch information
liubao68 authored May 24, 2022
1 parent c20786d commit 9c82151
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,30 @@

@Configuration
@ConditionalOnClass(name = "org.springframework.web.servlet.config.annotation.WebMvcConfigurer")
public class WebmvcConfiguration implements WebMvcConfigurer {
private List<PreHandlerInterceptor> preHandlerInterceptors;

private List<PostHandlerInterceptor> postHandlerInterceptors;

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new DecorateHandlerInterceptor(preHandlerInterceptors, postHandlerInterceptors))
.addPathPatterns("/**");
public class WebMvcConfiguration {
static class WebMvcConfigurerBean implements WebMvcConfigurer {
private List<PreHandlerInterceptor> preHandlerInterceptors;

private List<PostHandlerInterceptor> postHandlerInterceptors;

WebMvcConfigurerBean(List<PreHandlerInterceptor> preHandlerInterceptors,
List<PostHandlerInterceptor> postHandlerInterceptors) {
this.preHandlerInterceptors = preHandlerInterceptors;
this.postHandlerInterceptors = postHandlerInterceptors;
}

@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new DecorateHandlerInterceptor(preHandlerInterceptors, postHandlerInterceptors))
.addPathPatterns("/**");
}
}

@Autowired(required = false)
public void setPreHandlerInterceptors(List<PreHandlerInterceptor> preHandlerInterceptors) {
this.preHandlerInterceptors = preHandlerInterceptors;
}

@Autowired(required = false)
public void setPostHandlerInterceptors(List<PostHandlerInterceptor> postHandlerInterceptors) {
this.postHandlerInterceptors = postHandlerInterceptors;
@Bean
public WebMvcConfigurer webMvcConfigurer(
@Autowired(required = false) List<PreHandlerInterceptor> preHandlerInterceptors,
@Autowired(required = false) List<PostHandlerInterceptor> postHandlerInterceptors) {
return new WebMvcConfigurerBean(preHandlerInterceptors, postHandlerInterceptors);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ org.springframework.cloud.bootstrap.BootstrapConfiguration=\
com.huaweicloud.common.CommonConfiguration
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.huaweicloud.common.adapters.web.WebConfiguration,\
com.huaweicloud.common.adapters.webmvc.WebmvcConfiguration,\
com.huaweicloud.common.adapters.webmvc.WebMvcConfiguration,\
com.huaweicloud.common.adapters.feign.FeignConfiguration,\
com.huaweicloud.common.adapters.gateway.GatewayConfiguration

0 comments on commit 9c82151

Please sign in to comment.