package com.xcong.farmer.cms.configurations; import com.xcong.farmer.cms.utils.SpringContextHolder; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.SpringBootConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; /** * @author wzy * @date 2020-04-27 11:54 **/ @SpringBootConfiguration @Slf4j public class WebMvcConfig implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { } /** * 设置cors跨域支持 * * @param registry */ @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins("*") .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS") .allowCredentials(true).maxAge(3600); } @Bean public SpringContextHolder springContextHolder() { return new SpringContextHolder(); } }