일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 음악작곡기초
- 음계구조
- 삼성기출
- SW 직군
- 무료 악보 프로그램
- 대중음악화성
- 스케일분석
- 삼성전자
- 평행조
- syncroom
- 화성학응용
- ableton live 12
- 마법사상어와 블리자드
- 화음분석
- 코딩테스트
- mode chord
- Java
- 음정이론
- DP
- code tree
- 모드코드
- 취준
- 모달진행
- 코테
- 알고리즘
- 공대생 자소서
- 드럼Tab악보
- 코드차용
- 코드트리
- 삼성SW Expert Academy
- Today
- Total
Code Beat
stompCORS 본문
3년 전 Spring Boot 토이프로젝트 당시
stomp 연결에서 발생 했던 에러에 관한 정리 글을 이전한다.
간단한 토이프로젝트를 진행하면서
Stomp로 최초 소켓 연결에서 CORS 에러를 해결하던 중
어이없는 문제로 시간을 소요하여 우선 간단히 정리해두려한다.
기본적인 Stomp 연결을 로컬 혹은 CORS 문제가 발생하지 않을 환경에서 동작한다는 전제 하에
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/websocket").withSockJS();
}
위와 같은 코드가 Socket Config를 설정하는 Java class 내부에 있을 것이다.
구글링했을 때
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/websocket").setAllowedOrigins("*").withSockJS();
}
위처럼 setAllowedOrigins 를 통해 허용해주면 된다! 라고 한다.
하지만
java.lang.IllegalArgumentException: When allowCredentials is true,
allowedOrigins cannot contain the special value "*"since that cannot be set on the
"Access-Control-Allow-Origin" response header. To allow credentials to a set of origins,
list them explicitly or consider using "allowedOriginPatterns" instead.
이와 같은 에러를 만났고, 간단히 해석했을 때는
allowCredential 이 true 일때는 “*”로 CORS를 허용해줄 수 없다는 것인데
https://github.com/spring-projects/spring-framework/issues/26111
Not possible to use allowedOrigins "*" in StompEndpointRegistry after upgrade to Spring Boot 2.4.0 · Issue #26111 · spring-pro
Not sure if this should be filed under Spring Boot or Spring framework, but I put it here since Spring Boot Starter is in use. After upgrading to use Spring Boot 2.4.0 from 2.3.x, it does not seem ...
github.com
위의 링크에서 issue로 다룬 내용을 보면 2.4.0 버전이 되면서 문제가 발생하였고,
setAllowedOrigins 대신 setAllowedOriginsPatterns 를 사용해 해결할 수 있다고 한다.
얕은 지식으로 음 CORS 처리를 해줘야지하고, 어노테이션, config 세팅을 했는데
왜 안될까..? 하고 한참을 찾아다녔다.
Stomp의 CORS 세팅을 별개로 해주어야 하는 것과 에러를 꼼꼼히 읽어보자.. 라는 교훈을 얻었다.
사실 제일 처음 에러의 마지막을 읽어보면 이미 해결책을 말해주고 있었다
'Code > 코딩 끄적' 카테고리의 다른 글
[JAVA] Reflection (0) | 2024.03.24 |
---|---|
JPA (0) | 2024.03.24 |
strictfp (Strict Floating Point) (0) | 2024.03.03 |