package com.jpsoft.bus.config; import com.jpsoft.bus.interceptor.LoginInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.*; @Configuration public class WebMvcConfig implements WebMvcConfigurer { @Autowired private LoginInterceptor loginInterceptor; @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins("*") .allowedHeaders("*") .allowedMethods("*") .allowCredentials(false) .exposedHeaders("access-control-allow-headers", "access-control-allow-methods", "access-control-allow-origin", "access-control-max-age", "X-Frame-Options", "token-status") .maxAge(3600); } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/"); registry.addResourceHandler("swagger-ui.html") .addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**") .addResourceLocations("classpath:/META-INF/resources/webjars/"); } @Override public void addViewControllers(ViewControllerRegistry registry) { // registry.addViewController("/login").setViewName("login"); } @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(loginInterceptor) .addPathPatterns("/**") .excludePathPatterns("/login", "/swagger-resources/**", "/webjars/**", "/swagger-ui.html", "/doc.html", "/v2/**", "/mobileApi/**") .excludePathPatterns("/mobile/passengerApi/getVerifyCode") .excludePathPatterns("/mobile/passengerApi/validateCode") .excludePathPatterns("/mobile/driverApi/carActivation") .excludePathPatterns("/mobile/driverApi/findByPhone") .excludePathPatterns("/mobile/passengerApi/getShiftInfo") .excludePathPatterns("/mobile/passengerApi/upload") .excludePathPatterns("/wechat/findUserInfo/**") ; } }