12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package com.fd.config;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.web.servlet.config.annotation.CorsRegistry;
- import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
- import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
- /**
- * Created by Owen on 2019/10/25 0025 16:29
- */
- @Configuration
- public class WebMvcConfg implements WebMvcConfigurer {
- @Bean
- public MyInterceptor myInterceptor(){
- return new MyInterceptor();
- }
- /**
- * 重写addInterceptors方法
- * addPathPatterns:需要拦截的访问路径
- * excludePathPatterns:不需要拦截的路径,
- * String数组类型可以写多个用","分割
- */
- @Override
- public void addInterceptors(InterceptorRegistry registry) {
- registry.addInterceptor(myInterceptor())
- // .addPathPatterns("/**")
- .addPathPatterns("/api/vts/**")
- .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html");
- }
- /**
- * 配置全局跨域
- */
- @Override
- public void addCorsMappings(CorsRegistry registry) {
- registry.addMapping("/**")
- .allowedOrigins("*")
- .allowCredentials(true)
- .allowedMethods("GET", "POST", "DELETE", "PUT", "OPTIONS")
- .maxAge(3600);
- }
- }
|