Skip to content

Commit

Permalink
Update 比较重要的类的讲解.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Snailclimb committed Oct 11, 2019
1 parent 1513df5 commit 88e77f3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/比较重要的类的讲解.md
Expand Up @@ -381,3 +381,24 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {

```

**跨域:**

在这里踩的一个坑是:如果你没有设置`exposedHeaders("Authorization")`暴露 header 中的"Authorization"属性给客户端应用程序的话,前端是获取不到 token 信息的。

```java
@Configuration
public class CorsConfiguration implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
//暴露header中的其他属性给客户端应用程序
//如果不设置这个属性前端无法通过response header获取到Authorization也就是token
.exposedHeaders("Authorization")
.allowCredentials(true)
.allowedMethods("GET", "POST", "DELETE", "PUT")
.maxAge(3600);
}
}
```

0 comments on commit 88e77f3

Please sign in to comment.