1
1
.
.
9
9
.
.
5
5
C
C
O
O
R
R
S
S
-
-
E
E
n
n
a
a
b
b
l
l
e
e
d
d
-
-
A
A
P
P
I
I
I
I
n
n
f
f
o
o
This tutorial shows how to enable CORS in Destination Application by using API in newly created Class WebConfig.java.
Destination Application Schema [Results]
C
C
h
h
a
a
n
n
g
g
e
e
s
s
i
i
n
n
D
D
e
e
s
s
t
t
i
i
n
n
a
a
t
t
i
i
o
o
n
n
A
A
p
p
p
p
l
l
i
i
c
c
a
a
t
t
i
i
o
o
n
n
Create Package: config (inside main package)
Create Class: WebConfig.java (inside package config)
WebConfig.java
package com.ivoronline.springboot_cors_destination.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/Hello").allowedMethods("GET", "POST", "PUT");
}
}
MyController
http://localhost:8080/hello
Tomcat
sayHello()
Browser
WebConfig
R
R
e
e
s
s
u
u
l
l
t
t
s
s
Start Source Application
Start Destination Application
http://localhost:8080
Customize and control Google Chrome
More Tools
Developer Tools
Network
http://localhost:8080/Hello (no CORS error)
Destination Application Structure