package com.owl.config.interceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import lombok.extern.slf4j.Slf4j;
@Configuration
@Slf4j
public class InterceptorConfig implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(globalInterceptor()).addPathPatterns("/**");
log.info("系统拦截器初始化完成");
}
@Bean
public GlobalInterceptor globalInterceptor() {
return new GlobalInterceptor();
}
@Override
public void addCorsMappings(CorsRegistry registry) {
CorsRegistration cors = registry.addMapping("/**");
cors.allowedOrigins("*");
cors.allowedHeaders("*");
cors.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS");
cors.maxAge(3600);
}
}