本文主要是介绍springboot vue 每次请求jsessionid都不一样的问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、前端:axios增加属性withCredentials:true
const service = axios.create({baseUrl: 'http://xxxxxxxx',withCredentials: true,timeout: 60000
})
2、后端1:修改配置文件,设置addAllowedOriginPattern,addAllowedHeader,setAllowCredentials属性
@Configuration
public class VeWebMvcConfigurer implements WebMvcConfigurer {@Beanpublic CorsFilter corsFilter() {CorsConfiguration config = new CorsConfiguration();config.addAllowedMethod(HttpMethod.GET);config.addAllowedMethod(HttpMethod.POST);config.addAllowedMethod(HttpMethod.DELETE);config.addAllowedMethod(HttpMethod.PUT);config.addAllowedMethod(HttpMethod.OPTIONS);config.addAllowedOriginPattern("*");config.addAllowedHeader("*");config.setAllowCredentials(true);UrlBasedCorsConfigurationSource corsConfigurationSource = new UrlBasedCorsConfigurationSource();corsConfigurationSource.registerCorsConfiguration("/**", config);return new CorsFilter(corsConfigurationSource);}
}
3、后端2:在继承了WebSecurityConfigurerAdapter的类中的configure方法里设置属性sessionManagement().sessionFixation().changeSessionId().disable()
重启前后端项目看看jsessionid是不是固定了
这篇关于springboot vue 每次请求jsessionid都不一样的问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!