Spring Web配置自动添加HandlerInterceptorAdapter

时间:2019-04-05 09:33:05

标签: spring configuration spring-web spring-boot-starter

我已配置共享库,以便有机会将开发的功能立即投入我的Web服务中。

  @Configuration
  @ComponentScan({
      "common.logging.restapi.service",
      "common.logging.restapi.interceptor",
  })
  @Slf4j
  public class WebRestApiStopWatchConfiguration implements WebMvcConfigurer {

    @Autowired
    private RestLoggingInterceptor restLoggingInterceptor;

    @PostConstruct
    public void post() {
      log.info("WebRestApiStopWatchConfiguration post constructor.");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
      log.info("adding interceptor(s).");
      registry.addInterceptor(restLoggingInterceptor);
    }

  }
如果没有更多的Web配置,则

所示的代码部分将完美工作。万一我尝试将库添加到存在其他配置的应用程序中(例如,交错的Web配置)

@Configuration
@EnableSwagger2
@Slf4j
public class SwaggerConfiguration extends WebMvcConfigurationSupport {

方法addInterceptors(InterceptorRegistry registry)从未在配置时使用。

问题

总的来说,我很有趣地自动注册了一些自定义HandlerInterceptor。考虑到这种具体情况,我需要在注入库的项目中进行WebRestApiStopWatchConfiguration.#addInterceptors的加载而无需注入。

0 个答案:

没有答案
相关问题