WebMvcConfig.java 1.5 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 WebMvcConfig implements WebMvcConfigurer {
  12. // @Bean
  13. // public MyInterceptor myInterceptor(){
  14. // return new MyInterceptor();
  15. // }
  16. //
  17. // /**
  18. //   * 重写addInterceptors方法
  19. //   * addPathPatterns:需要拦截的访问路径
  20. //   * excludePathPatterns:不需要拦截的路径,
  21. //   * String数组类型可以写多个用","分割
  22. //   */
  23. // @Override
  24. // public void addInterceptors(InterceptorRegistry registry) {
  25. // registry.addInterceptor(myInterceptor())
  26. // .addPathPatterns("/**")
  27. // .excludePathPatterns("/api/**")
  28. // .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html");
  29. // }
  30. /**
  31. * 配置全局跨域
  32. */
  33. @Override
  34. public void addCorsMappings(CorsRegistry registry) {
  35. registry.addMapping("/**")
  36. .allowedOrigins("*")
  37. .allowCredentials(true)
  38. .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
  39. .maxAge(3600);
  40. }
  41. }