前言
跨域問題的基本處理查看上一篇文章:https://blog.csdn.net/Mint6/article/details/104468530,這個可以解決大部分問題。
如果是使用的shiro以上步驟都試過了,還有如下問題,請看本文章的解決辦法。
問題
把主要提示拷貝出來
A cookie associated with a cross-site resource at http://127.0.0.1/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
跨域問題導致的,cookie帶不過去,重定向失敗。
解決辦法
按如下增加配置
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;
/**
* @Auther: Administrator
* @Date:
* @Description:
*/
@Configuration
public class CorsConfig {
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);
}
}
最後:這個是針對shiro特殊情況的處理,如果是有跨域問題還沒定位問題請先看跨域的基本處理辦法:https://blog.csdn.net/Mint6/article/details/104468530