Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
liyeyun-user-web
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cfld-backend
liyeyun-user-web
Commits
f923798f
Commit
f923798f
authored
Dec 16, 2023
by
yaobaizheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
跨域请求
parent
a6e8cb20
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
0 deletions
+24
-0
WebConfig.java
src/main/java/com/lyy/user/config/auth/WebConfig.java
+24
-0
No files found.
src/main/java/com/lyy/user/config/auth/WebConfig.java
View file @
f923798f
...
@@ -5,6 +5,9 @@ import org.springframework.context.annotation.Bean;
...
@@ -5,6 +5,9 @@ import org.springframework.context.annotation.Bean;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.StringHttpMessageConverter
;
import
org.springframework.http.converter.StringHttpMessageConverter
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.EnableWebMvc
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
import
org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
;
...
@@ -96,4 +99,25 @@ public class WebConfig implements WebMvcConfigurer {
...
@@ -96,4 +99,25 @@ public class WebConfig implements WebMvcConfigurer {
Collections
.
addAll
(
list
,
swagger
());
Collections
.
addAll
(
list
,
swagger
());
return
list
;
return
list
;
}
}
@Bean
public
CorsFilter
corsFilter
()
{
CorsConfiguration
config
=
new
CorsConfiguration
();
config
.
setAllowCredentials
(
true
);
// 设置访问源地址
config
.
addAllowedOriginPattern
(
"*"
);
// 设置访问源请求头
config
.
addAllowedHeader
(
"*"
);
// 设置访问源请求方法
config
.
addAllowedMethod
(
"*"
);
// 有效期 3600秒
config
.
setMaxAge
(
3600L
);
// 添加映射路径,拦截一切请求
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
source
.
registerCorsConfiguration
(
"/**"
,
config
);
// 返回新的CorsFilter
return
new
CorsFilter
(
source
);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment