8000 Server:允许发送跨域凭据;修改工程名 · CodingJun/APIJSON@fe2713e · GitHub
[go: up one dir, main page]

Skip to content

Commit fe2713e

Browse files
committed
Server:允许发送跨域凭据;修改工程名
1 parent 3d5c952 commit fe2713e

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

APIJSON-Java-Server/APIJSON-Eclipse/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<version>0.0.1-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010

11-
<name>APIJSON(Idea)</name>
11+
<name>APIJSON</name>
1212
<description>APIJSON Server project using Spring Boot</description>
1313

1414
<parent>

APIJSON-Java-Server/APIJSON-Eclipse/src/main/java/apijson/demo/server/APIJSONApplication.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,18 @@ public static void main(String[] args) throws Exception {
5757
@Bean
5858
public CorsFilter corsFilter() {
5959
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
60-
source.registerCorsConfiguration("/**", buildConfig()); // 4
60+
source.registerCorsConfiguration("/**", buildConfig());
6161
return new CorsFilter(source);
6262
}
6363
/**CORS跨域配置
6464
* @return
6565
*/
6666
private CorsConfiguration buildConfig() {
6767
CorsConfiguration corsConfiguration = new CorsConfiguration();
68-
corsConfiguration.addAllowedOrigin("*");
69-
corsConfiguration.addAllowedHeader("*");
70-
corsConfiguration.addAllowedMethod("*");
68+
corsConfiguration.addAllowedOrigin("*"); //允许的域名或IP地址
69+
corsConfiguration.addAllowedHeader("*"); //允许的请求头
70+
corsConfiguration.addAllowedMethod("*"); //允许的HTTP请求方法
71+
corsConfiguration.setAllowCredentials(true); //允许发送跨域凭据,前端Axios存取JSESSIONID必须要
7172
return corsConfiguration;
7273
}
7374
//支持JavaScript跨域请求 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

0 commit comments

Comments
 (0)
0