com.github.mengweijin.quickboot.framework.web.QuickBootWebMvcAutoConfiguration Maven / Gradle / Ivy
package com.github.mengweijin.quickboot.framework.web;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import java.util.List;
/**
* @author Meng Wei Jin
* @description
**/
@Configuration
public class QuickBootWebMvcAutoConfiguration implements WebMvcConfigurer {
@Autowired
private PageArgumentResolver pageArgumentResolver;
@Value("${quickboot.cors: false}")
private boolean cors;
/**
* 跨域
* @param registry CorsRegistry
*/
@Override
public void addCorsMappings(CorsRegistry registry) {
if(cors) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedHeaders("*")
.allowedMethods("*")
.allowCredentials(true)
.maxAge(3600);
}
}
/**
* 注册参数解析器
* @param argumentResolvers
*/
@Override
public void addArgumentResolvers(List argumentResolvers) {
argumentResolvers.add(pageArgumentResolver);
}
}