WebMvcConfg.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.fd.config;
  2. import org.springframework.context.annotation.Bean;
  3. import org.springframework.context.annotation.Configuration;
  4. import org.springframework.web.servlet.config.annotation.CorsRegistry;
  5. import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
  6. import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
  7. /**
  8. * Created by Owen on 2019/10/25 0025 16:29
  9. */
  10. @Configuration
  11. public class WebMvcConfg implements WebMvcConfigurer {
  12. @Bean
  13. public MyInterceptor myInterceptor(){
  14. return new MyInterceptor();
  15. }
  16. /**
  17.   * 重写addInterceptors方法
  18.   * addPathPatterns:需要拦截的访问路径
  19.   * excludePathPatterns:不需要拦截的路径,
  20.   * String数组类型可以写多个用","分割
  21.   */
  22. @Override
  23. public void addInterceptors(InterceptorRegistry registry) {
  24. registry.addInterceptor(myInterceptor())
  25. // .addPathPatterns("/**")
  26. .addPathPatterns("/api/vts/**")
  27. .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html");
  28. }
  29. /**
  30. * 配置全局跨域
  31. */
  32. @Override
  33. public void addCorsMappings(CorsRegistry registry) {
  34. registry.addMapping("/**")
  35. .allowedOrigins("*")
  36. .allowCredentials(true)
  37. .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
  38. .maxAge(3600);
  39. }
  40. }