Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
d23405ec
Commit
d23405ec
authored
Mar 25, 2020
by
yuquan.zhu
Committed by
chenzg
Jul 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改跨域访问
parent
ca0b5f60
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
src/main/java/cn/timer/api/Application.java
+19
-0
src/main/java/cn/timer/api/config/interceptor/WebSecurityConfig.java
+10
-0
No files found.
src/main/java/cn/timer/api/Application.java
View file @
d23405ec
...
@@ -11,6 +11,9 @@ import org.springframework.http.converter.HttpMessageConverter;
...
@@ -11,6 +11,9 @@ import org.springframework.http.converter.HttpMessageConverter;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.transaction.annotation.EnableTransactionManagement
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.client.RestTemplate
;
import
org.springframework.web.cors.CorsConfiguration
;
import
org.springframework.web.cors.UrlBasedCorsConfigurationSource
;
import
org.springframework.web.filter.CorsFilter
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
import
com.alibaba.fastjson.support.config.FastJsonConfig
;
import
com.alibaba.fastjson.support.config.FastJsonConfig
;
...
@@ -63,6 +66,22 @@ public class Application {
...
@@ -63,6 +66,22 @@ public class Application {
public
RestTemplate
getRestTemplate
()
{
public
RestTemplate
getRestTemplate
()
{
return
restTemplateBuilder
.
build
();
return
restTemplateBuilder
.
build
();
}
}
private
CorsConfiguration
buildConfig
()
{
CorsConfiguration
corsConfiguration
=
new
CorsConfiguration
();
corsConfiguration
.
addAllowedOrigin
(
"*"
);
// 1允许任何域名使用
corsConfiguration
.
addAllowedHeader
(
"*"
);
// 2允许任何头
corsConfiguration
.
addAllowedMethod
(
"*"
);
// 3允许任何方法(post、get等)
corsConfiguration
.
setAllowCredentials
(
true
);
return
corsConfiguration
;
}
@Bean
public
CorsFilter
corsFilter
()
{
UrlBasedCorsConfigurationSource
source
=
new
UrlBasedCorsConfigurationSource
();
source
.
registerCorsConfiguration
(
"/**"
,
buildConfig
());
// 4
return
new
CorsFilter
(
source
);
}
// @Override
// @Override
// protected SpringApplicationBuilder configure(SpringApplicationBuilder
// protected SpringApplicationBuilder configure(SpringApplicationBuilder
...
...
src/main/java/cn/timer/api/config/interceptor/WebSecurityConfig.java
View file @
d23405ec
...
@@ -10,6 +10,7 @@ import org.springframework.context.annotation.Configuration;
...
@@ -10,6 +10,7 @@ import org.springframework.context.annotation.Configuration;
import
org.springframework.http.MediaType
;
import
org.springframework.http.MediaType
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.http.converter.HttpMessageConverter
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.method.support.HandlerMethodArgumentResolver
;
import
org.springframework.web.servlet.config.annotation.CorsRegistry
;
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
;
...
@@ -79,4 +80,13 @@ public class WebSecurityConfig implements WebMvcConfigurer {
...
@@ -79,4 +80,13 @@ public class WebSecurityConfig implements WebMvcConfigurer {
argumentResolvers
.
add
(
userMethodArgumentResolver
);
argumentResolvers
.
add
(
userMethodArgumentResolver
);
}
}
// @Override
// public void addCorsMappings(CorsRegistry registry) {
// registry.addMapping("/**")
// .allowedOrigins("*")
// .allowCredentials(true)
// .allowedMethods("GET", "POST", "DELETE", "PUT","PATCH")
// .maxAge(3600);
// }
}
}
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