[SpringBoot] 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... 어쩌고저쩌고.. 오류 해결하기 🤔

2025. 4. 17. 12:23·Develop/Trouble Shooting
반응형

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.

 

 

스프링부트에서 웹소켓 서버를 만들어서

간단한 플레시게임을 만드려고 했는데

 

엥?? 이전에는 이렇게 작성하면 별 문제 없었는데??
모든 Access-Control-Allow-Origin * 설정했는데??
뭐가 변경된거지?????? 😡 😡 😡 😡

 

 

현재 내 웹 컨픽, 소켓 설정은 아래와 같다.

 

package com.car.ndj.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("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET","POST","PUT","DELETE","OPTIONS")
                .allowedHeaders("*")
                .allowCredentials(true);
    }
}

 

package com.car.ndj.config;

import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
@RequiredArgsConstructor
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/ws").setAllowedOriginPatterns("*").withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry config) {
        config.enableSimpleBroker("/topic"); // 구독 prefix
        config.setApplicationDestinationPrefixes("/app"); // 송신 prefix
    }
}

 

 

 setAllowedOrigins -> setAllowedOriginPatterns


사실 오류 내용을 직역하면

 


allowCredentials가 true인 경우, allowedOrigins는 "Access-Control-Allow-Origin" 응답 헤더에 설정할 수 없는 특수 값 "*"를 포함할 수 없습니다. 특정 출처 집합에 대한 자격 증명을 허용하려면 해당 출처 집합을 명시적으로 나열하거나 "allowedOriginPatterns"를 사용하는 것이 좋습니다

 

해결 방법이 다 있다.

allowedOrigin("*") 과 allowCredentials(true) 는 동시에 설정할 수 없는데

이 부분은 추후에 시간이 나면 내부 소스를 따라가보도록 하자 😩

 

 

웹소켓 설정과 웹 컨픽 설정을 수정하여 해결 할 수 있다. 🤔

 

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.

 

 

반응형
저작자표시 비영리 (새창열림)

'Develop > Trouble Shooting' 카테고리의 다른 글

[Docker] 도커로 환경을 옮긴 후 셀레니움이 실행이 안되는 오류 해결  (3) 2025.04.24
API 동시성 문제 개선하기 (MAX + 1 Key 채번)😡  (6) 2025.02.04
[Request processing failed: org.springframework.jdbc.UncategorizedSQLException: Error attempting to get column '컬럼명' from result set. Cause: java.sql.SQLException: 부적합한 열 유형: getBLOB not implemented for class oracle.jdbc.driver.T4CLongRawAccessor 오류 해결 하  (9) 2024.10.28
uncategorized SQLException; SQL state [99999]; error code [17056]; 지원되지 않는 문자 집합(클래스 경로에 orai18n.jar 추가): KO16KSC5601 에러 해결 방법! 🛠️  (2) 2024.08.30
'Develop/Trouble Shooting' 카테고리의 다른 글
  • [Docker] 도커로 환경을 옮긴 후 셀레니움이 실행이 안되는 오류 해결
  • API 동시성 문제 개선하기 (MAX + 1 Key 채번)😡
  • [Request processing failed: org.springframework.jdbc.UncategorizedSQLException: Error attempting to get column '컬럼명' from result set. Cause: java.sql.SQLException: 부적합한 열 유형: getBLOB not implemented for class oracle.jdbc.driver.T4CLongRawAccessor 오류 해결 하
  • uncategorized SQLException; SQL state [99999]; error code [17056]; 지원되지 않는 문자 집합(클래스 경로에 orai18n.jar 추가): KO16KSC5601 에러 해결 방법! 🛠️
    반응형
  • 개발자는어디까지공부해야할까?
  • 전체
    오늘
    어제
    • 분류 전체보기 (53)
      • 인디해커 (1)
      • Develop (42)
        • Front-End (7)
        • Back-End (17)
        • Spring (1)
        • Tool (1)
        • DATABASE (1)
        • DevOps (7)
        • CS (3)
        • Trouble Shooting (5)
      • 다이소 (1)
        • 코딩테스트문제풀이 (1)
      • 변소 (9)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • 깃허브(Github)
    • 개발 Feed
  • 공지사항

  • 인기 글

  • 태그

    fow.kr
    SpringBoot
    spring boot
    Recoil
    롤
    lol
    백엔드 개발자 면접 단골 질문 뿌시기
    github
    thymeleaf
    리액트
    node
    mybatis
    JavaScript
    백엔드
    spring
    backend
    개발자 면접
    리그오브레전드
    react-router-dom
    op.gg
    타임리프 사용방법
    jdk
    @Scheduled
    스프링부트
    React
    자바
    셀레니움
    개발자
    Java
    Oracle
  • 최근 댓글

  • 최근 글

  • 07-14 01:06
  • hELLO· Designed By정상우.v4.10.3
[SpringBoot] 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... 어쩌고저쩌고.. 오류 해결하기 🤔
상단으로

티스토리툴바