Skip to content

Commit 53ccdfc

Browse files
Explaining How CORS works in SB
1 parent e50800c commit 53ccdfc

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Spring_Boot/CORS/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
### CORS In Spring Boot
2+
3+
4+
5+
```java
6+
package com.starter.springboot;
7+
8+
import org.springframework.context.annotation.Configuration;
9+
import org.springframework.web.servlet.config.annotation.CorsRegistry;
10+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
11+
12+
@Configuration
13+
public class AppConf implements WebMvcConfigurer {
14+
15+
@Override
16+
public void addCorsMappings(CorsRegistry registry) {
17+
//enabling CORS
18+
registry.addMapping("/**")
19+
//setting the allowed origin
20+
.allowedOrigins("http://localhost:4200")
21+
//setting the allowed request Method
22+
.allowedMethods("GET");
23+
}
24+
}
25+
```

0 commit comments

Comments
 (0)