MyWebMvcConfig.java 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. package com.seecoder.BlueWhale.configure;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  5. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  6. /**
  7. * @Author: DingXiaoyu
  8. * @Date: 0:17 2023/11/26
  9. *
  10. * 这个类实现了WebMvcConfigurer接口,
  11. * 表示会被SpringBoot接受,
  12. * 这个类的作用是配置拦截器。
  13. * addInterceptors方法配置了拦截器,
  14. * 添加了loginInterceptor作为拦截器,
  15. * 并且设置除了register和login的所有接口都需要通过该拦截器。
  16. */
  17. @Configuration
  18. public class MyWebMvcConfig implements WebMvcConfigurer {
  19. @Autowired
  20. LoginInterceptor loginInterceptor;
  21. @Override
  22. public void addInterceptors(InterceptorRegistry registry) {
  23. registry.addInterceptor(loginInterceptor)
  24. .addPathPatterns("/**")
  25. .excludePathPatterns("/api/users/register")
  26. .excludePathPatterns("/api/users/login")
  27. .excludePathPatterns("/api/ali/*")
  28. .order(1);
  29. }
  30. }