Angular中请求Spring Boot接口缺少X-Application-Context报错

Angular中请求Spring Boot接口缺少X-Application-Context报错

可以再Spring Boot的配置文件Application.yml中增加:

1
2
management: 
add-application-context-header: false


同时处理跨域的问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@Configuration
public class CORSConfiguration {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedHeaders("*")
.allowedMethods("*")
.allowedOrigins("*");
}
};
}
}

引用:
https://stackoverflow.com/questions/40379550/what-is-x-application-context-header