Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MicroCommunity
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
langhongbin
MicroCommunity
Commits
e26af6ad
Commit
e26af6ad
authored
Oct 19, 2023
by
luyuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
8650d0f9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
2 deletions
+30
-2
java110-core/src/main/java/com/java110/core/base/controller/BaseController.java
...java/com/java110/core/base/controller/BaseController.java
+2
-1
java110-service/src/main/java/com/java110/service/configuration/CustomMVCConfiguration.java
...java110/service/configuration/CustomMVCConfiguration.java
+1
-1
springboot/src/main/java/com/java110/boot/configuration/ServiceConfiguration.java
.../com/java110/boot/configuration/ServiceConfiguration.java
+27
-0
No files found.
java110-core/src/main/java/com/java110/core/base/controller/BaseController.java
View file @
e26af6ad
...
...
@@ -30,7 +30,7 @@ import java.util.*;
* Created by wuxw on 2017/2/23.
*/
@CrossOrigin
@CrossOrigin
(
origins
=
"*"
,
allowedHeaders
=
"*"
,
maxAge
=
86400
)
public
class
BaseController
extends
AppBase
{
...
...
@@ -195,6 +195,7 @@ public class BaseController extends AppBase {
headers
.
put
(
"user_id"
,
headers
.
get
(
"user-id"
));
}
headers
.
put
(
"Access-Control-Allow-Origin"
,
"*"
);
}
/**
...
...
java110-service/src/main/java/com/java110/service/configuration/CustomMVCConfiguration.java
View file @
e26af6ad
...
...
@@ -53,6 +53,6 @@ public class CustomMVCConfiguration extends WebMvcConfigurerAdapter {
private
static
final
String
ORIGINS
[]
=
new
String
[]
{
"GET"
,
"POST"
,
"PUT"
,
"DELETE"
};
@Override
public
void
addCorsMappings
(
CorsRegistry
registry
)
{
registry
.
addMapping
(
"/**"
).
allowedOrigins
(
"*"
).
allow
Credentials
(
true
).
allowedMethods
(
ORIGINS
).
maxAge
(
3600
);
registry
.
addMapping
(
"/**"
).
allowedOrigins
(
"*"
).
allow
edMethods
(
"*"
).
allowedHeaders
(
"*"
);
}
}
springboot/src/main/java/com/java110/boot/configuration/ServiceConfiguration.java
View file @
e26af6ad
...
...
@@ -4,6 +4,10 @@ import com.java110.boot.filter.JwtFilter;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.core.Ordered
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
/**
* Created by wuxw on 2018/5/2.
...
...
@@ -121,4 +125,27 @@ public class ServiceConfiguration {
return
registrationBean
;
}
@Bean
public
FilterRegistrationBean
corsFilter
()
{
// 创建 CorsConfiguration 对象后添加配置
CorsConfiguration
corsConfiguration
=
new
CorsConfiguration
();
corsConfiguration
.
setAllowCredentials
(
true
);
// 设置放行哪些原始域
corsConfiguration
.
addAllowedOrigin
(
"*"
);
// 放行哪些原始请求头部信息
corsConfiguration
.
addAllowedHeader
(
"*"
);
// 放行哪些请求方法
corsConfiguration
.
addAllowedMethod
(
"*"
);
// 添加映射路径
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
source
.
registerCorsConfiguration
(
"/**"
,
corsConfiguration
);
CorsFilter
corsFilter
=
new
CorsFilter
(
source
);
FilterRegistrationBean
<
CorsFilter
>
registrationBean
=
new
FilterRegistrationBean
<>();
registrationBean
.
setFilter
(
corsFilter
);
registrationBean
.
setOrder
(
Ordered
.
HIGHEST_PRECEDENCE
);
return
registrationBean
;
}
}
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