【发布时间】:2020-08-29 00:20:10
【问题描述】:
我在 Angular 项目中第一次使用 Spring Boot,在添加 Spring 安全依赖项之前一切正常
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
现在我在客户端收到此错误:
Access to XMLHttpRequest at 'http://localhost:8080/api/v1/login' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
我尝试按照文档的建议更改配置,所以我添加了类
src/main/java/com/example/securingweb/WebSecurityConfig.java
@Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer{
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}
}
我的控制器中也有这个:
@CrossOrigin(origins = "http://localhost:4200")
【问题讨论】:
标签: java spring spring-security