Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
S
shop
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
曲欣亮
shop
Commits
229dde85
Commit
229dde85
authored
Feb 24, 2023
by
张永
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
跨域
parent
38716cdc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
WebMvcConfig.java
src/main/java/com/egolm/shop/common/config/WebMvcConfig.java
+22
-0
No files found.
src/main/java/com/egolm/shop/common/config/WebMvcConfig.java
View file @
229dde85
...
@@ -2,6 +2,7 @@ package com.egolm.shop.common.config;
...
@@ -2,6 +2,7 @@ package com.egolm.shop.common.config;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistration
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistration
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.InterceptorRegistry
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurer
;
...
@@ -18,6 +19,27 @@ public class WebMvcConfig implements WebMvcConfigurer {
...
@@ -18,6 +19,27 @@ public class WebMvcConfig implements WebMvcConfigurer {
@Autowired
@Autowired
LogInterceptor
logInterceptor
;
LogInterceptor
logInterceptor
;
/**
*
* @Title: addCorsMappings
* @Description: TODO(解决跨域 https://www.toutiao.com/i6720374197358428685/)
* @param @param registry 设定文件
* @return 返回类型
* @throws
*/
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
registry
.
addMapping
(
"/**"
)
// 拦截所有的url
.
allowedOrigins
(
"*"
)
// 放行哪些原始域,比如"http://domain1.com,https://domain2.com"
.
allowCredentials
(
true
)
// 是否发送Cookie信息
.
allowedMethods
(
"GET"
,
"POST"
,
"PUT"
,
"DELETE"
)
// 放行哪些原始域(请求方式)
.
allowedHeaders
(
"*"
);
// 放行哪些原始域(头部信息)
WebMvcConfigurer
.
super
.
addCorsMappings
(
registry
);
}
@Override
@Override
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
public
void
addInterceptors
(
InterceptorRegistry
registry
)
{
InterceptorRegistration
logsRegistration
=
registry
.
addInterceptor
(
logInterceptor
).
addPathPatterns
(
"/**"
);
InterceptorRegistration
logsRegistration
=
registry
.
addInterceptor
(
logInterceptor
).
addPathPatterns
(
"/**"
);
...
...
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