Skip to content

Commit 100bcc5

Browse files
committed
更新SpringBoot2.1的WebMvcConfig配置
1 parent 67937e1 commit 100bcc5

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
package com.example.config;
22

33
import org.springframework.context.annotation.Configuration;
4+
import org.springframework.core.Ordered;
45
import org.springframework.web.servlet.config.annotation.CorsRegistry;
5-
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
6+
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
7+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
68

79
/**
8-
* SpringBoot全局支持CORS(跨源请求)的配置
10+
* 在SpringBoot2.0及Spring 5.0中WebMvcConfigurerAdapter以被废弃,建议实现WebMvcConfigurer接口
911
* @author Wang926454
10-
* @date 2018/8/9 17:28
12+
* @date 2019/1/24 19:17
1113
*/
1214
@Configuration
13-
public class WebMvcConfig extends WebMvcConfigurerAdapter {
15+
public class WebMvcConfig implements WebMvcConfigurer {
16+
17+
/**
18+
* SpringBoot全局支持CORS(跨源请求)的配置
19+
* @param registry
20+
* @return void
21+
* @author Wang926454
22+
* @date 2019/1/24 19:32
23+
*/
1424
@Override
1525
public void addCorsMappings(CorsRegistry registry) {
1626
registry.addMapping("/**").allowedOrigins("*")
17-
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
18-
.allowCredentials(false).maxAge(3600);
27+
.allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
28+
.allowCredentials(false).maxAge(3600);
1929
}
30+
2031
}

0 commit comments

Comments
 (0)