Commit 9fabaa02 authored by AfirSraftGarrier's avatar AfirSraftGarrier

接口文档

parent 62ef311c
package iot.sixiang.license.config; package iot.sixiang.license.config;
import org.springframework.context.annotation.Bean; import iot.sixiang.license.jwt.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
@Configuration @Configuration
public class CorsConfig { @EnableWebMvc
public class CorsConfig implements WebMvcConfigurer {
/** @Autowired
* 允许跨域调用的过滤器 AuthenticationInterceptor authenticationInterceptor;
*/
@Bean @Override
public CorsFilter corsFilter() { public void addCorsMappings(CorsRegistry registry) {
CorsConfiguration config = new CorsConfiguration(); registry.addMapping("/**")
//允许所有域名进行跨域调用 .allowedOriginPatterns("*")
//config.addAllowedOrigin("*"); .allowedMethods("*")
config.addAllowedOriginPattern("*"); .allowCredentials(true)
//允许跨越发送cookie .maxAge(3600)
config.setAllowCredentials(true); .allowedHeaders("*");
//放行全部原始头信息 }
config.addAllowedHeader("*");
//允许所有请求方法跨域调用 @Override
config.addAllowedMethod("*"); public void addResourceHandlers(ResourceHandlerRegistry registry) {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
source.registerCorsConfiguration("/**", config); registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
return new CorsFilter(source); }
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(authenticationInterceptor)
.addPathPatterns("/**");
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment