Nhu Nguyen 6 年前
父节点
当前提交
0cf157de43
共有 1 个文件被更改,包括 12 次插入0 次删除
  1. 12
    0
      src/main/java/com/example/demo/DemoApplication.java

+ 12
- 0
src/main/java/com/example/demo/DemoApplication.java 查看文件

@@ -3,7 +3,9 @@ package com.example.demo;
3 3
 import org.springframework.boot.SpringApplication;
4 4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 5
 import org.springframework.context.annotation.Bean;
6
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
6 7
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
8
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
7 9
 
8 10
 @SpringBootApplication
9 11
 public class DemoApplication {
@@ -11,4 +13,14 @@ public class DemoApplication {
11 13
 	public static void main(String[] args) {
12 14
 		SpringApplication.run(DemoApplication.class, args);
13 15
 	}
16
+
17
+	@Bean
18
+	public WebMvcConfigurer corsConfigurer() {
19
+		return new WebMvcConfigurerAdapter() {
20
+			@Override
21
+			public void addCorsMappings(CorsRegistry registry) {
22
+				registry.addMapping("*").allowedOrigins("http://localhost:9000");
23
+			}
24
+		};
25
+	}
14 26
 }