diff --git a/src/main/java/com/gitlink/softbot/config/AdminInterceptor.java b/src/main/java/com/gitlink/softbot/config/AdminInterceptor.java index f1a1e5f..c12f46b 100644 --- a/src/main/java/com/gitlink/softbot/config/AdminInterceptor.java +++ b/src/main/java/com/gitlink/softbot/config/AdminInterceptor.java @@ -1,21 +1,21 @@ -package com.gitlink.softbot.config; - -import org.springframework.stereotype.Component; -import org.springframework.web.filter.OncePerRequestFilter; - -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; - -@Component -public class AdminInterceptor extends OncePerRequestFilter { - - @Override - protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { - httpServletResponse.addHeader("Access-Control-Allow-Origin", "*"); - httpServletResponse.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT, HEAD,PATCH"); - filterChain.doFilter(httpServletRequest, httpServletResponse); - } -} +//package com.gitlink.softbot.config; +// +//import org.springframework.stereotype.Component; +//import org.springframework.web.filter.OncePerRequestFilter; +// +//import javax.servlet.FilterChain; +//import javax.servlet.ServletException; +//import javax.servlet.http.HttpServletRequest; +//import javax.servlet.http.HttpServletResponse; +//import java.io.IOException; +// +//@Component +//public class AdminInterceptor extends OncePerRequestFilter { +// +// @Override +// protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { +// httpServletResponse.addHeader("Access-Control-Allow-Origin", "*"); +// httpServletResponse.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT, HEAD,PATCH"); +// filterChain.doFilter(httpServletRequest, httpServletResponse); +// } +//} diff --git a/src/main/java/com/gitlink/softbot/config/CrossConfig.java b/src/main/java/com/gitlink/softbot/config/CrossConfig.java new file mode 100644 index 0000000..861e737 --- /dev/null +++ b/src/main/java/com/gitlink/softbot/config/CrossConfig.java @@ -0,0 +1,34 @@ +package com.gitlink.softbot.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.cors.CorsConfiguration; +import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.filter.CorsFilter; + +/** + * ClassName CrossConfig + * + * @author ZengWei + * Date 2021/7/15 + */ + +@Configuration +public class CrossConfig { + private CorsConfiguration buildConfig() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + corsConfiguration.addAllowedOrigin("*"); + corsConfiguration.addAllowedHeader("*"); + corsConfiguration.addAllowedMethod("*"); + corsConfiguration.setMaxAge(3600L); // 预检请求的有效期,单位为秒。 + corsConfiguration.setAllowCredentials(true);// 是否支持安全证书(必需参数) + return corsConfiguration; + } + + @Bean + public CorsFilter corsFilter() { + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", buildConfig()); + return new CorsFilter(source); + } +} diff --git a/target/classes/com/gitlink/softbot/controller/user/UserController.class b/target/classes/com/gitlink/softbot/controller/user/UserController.class index c8738f5..e326423 100644 Binary files a/target/classes/com/gitlink/softbot/controller/user/UserController.class and b/target/classes/com/gitlink/softbot/controller/user/UserController.class differ