报错404
找不到界面,排查了一系列问题发现是后端接口写错了,后端写的是
结果前端回调的时候用成了/account/register
报错405
大概看意思是不支持实现get方法,研究了一下,发现是我没有设置访问后端数据的get方法,和后端的业务逻辑没有关系
现在报的是500错误,排查了一圈,推测是过滤器问题,因为前端pyload也没有数据显示,后面发现果然是没有配置crosconfig
package com.example.demo.common.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;
@Configuration
public class CorsConfig {
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*"); // 1 设置访问源地址
corsConfiguration.addAllowedHeader("*"); // 2 设置访问源请求头
corsConfiguration.addAllowedMethod("*"); // 3 设置访问源请求方法
source.registerCorsConfiguration("/**", corsConfiguration); // 4 对接口配置跨域设置
return new CorsFilter(source);
}
}
在后端config文件夹加了这个文件之后好了
二编补充:
后续还是报500错,这次发现是因为token是空的没生成好