Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |
Tags
- ArrayList
- com.netflix.zuul.exception.ZuulException: Hystrix Readed time out
- emqx
- mariadb 한국어
- mstsc
- #spring boot admin
- 크로스도메인
- Access-Control-Allow-Origin
- Set
- cors
- IOT
- #actuator
- mosquitto
- HashMap
- #MSA
- 원격
- mqtt
- db utf8
- mysql 한국어
- message protocol
- backtracking
- mariadb 다국어
- java collection
- xrdp
- TreeMap
- Hystrix Read time out
- mysql 다국어
- CORS policy: No 'Access-Control-Allow-Origin'
- com.netflix.zuul.exception.ZuulException
- #spring boot
Archives
- Today
- Total
miin29na
[Spring] Access-Control-Allow-Origin 에러 본문
Spring 기반 Server Rest API 를 javascript 로 테스트 도중 다음과 같은 에러가 발생(크롬)
로컬 개발 서버에서는 Success, 원격 배포 서버에서는 Fail.
index.html:1 Access to XMLHttpRequest at 'http://원격지:8080/abc/' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
index2.html:154 {readyState: 0, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, override
Server side solution)
1.
1
2
3
4
5
6
7
8
9
|
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedOrigins("*");
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
or
2.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
@Bean
public CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();
configuration.addAllowedOrigin("*"); // CORS 요청 허용 Site
configuration.addAllowedMethod("*"); // CORS 요청 허용 Method Type (e.g. GET,PUT,POST)
configuration.addAllowedHeader("*"); // 특정 헤더 CORS 요청 허용
configuration.setAllowCredentials(true); // 자격증명과 함께 요청 여부 (Authorization로 사용자 인증 사용 시 true)
configuration.setMaxAge(3600L); // preflight request cache time
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
refrence link
https://brunch.co.kr/@adrenalinee31/1
https://spring.io/guides/gs/rest-service-cors/
Comments