No primary or single unique constructor found for interface org.springframework.security.oauth2.core.user.OAuth2User 해결하기

2025. 11. 3. 20:53·에러 수정일지
public ResponseEntity<LoginResponseDTO> success(HttpServletRequest request,
                                                    OAuth2User oAuth2User) {

        System.out.println(oAuth2User);

        if (loginSuccessService.checkEmail(oAuth2User.getAttribute("email"))) {
            HttpSession session = request.getSession();
            String email = oAuth2User.getAttribute("email");
            session.setAttribute("email", email);
            session.setMaxInactiveInterval(3600);
            
         ///생략
  }

스프링 OAuth2를 다루고 OAuth2 객체를 불러와 details를 뽑으려하니 저 에러가 터졌다.

 

에러메시지는

No primary or single unique constructor found for interface org.springframework.security.oauth2.core.user.OAuth2User

이렇게 되고...

에러의 원인은 매개변수로 넣어주는 OAuth2User 객체와 관련한 생성자를 찾을 수 없다는 뜻이다.

 

public ResponseEntity<LoginResponseDTO> success(HttpServletRequest request,
                                                    @AuthenticationPrincipal OAuth2User oAuth2User) {

        System.out.println(oAuth2User);

        if (loginSuccessService.checkEmail(oAuth2User.getAttribute("email"))) {
            HttpSession session = request.getSession();
            String email = oAuth2User.getAttribute("email");
            session.setAttribute("email", email);
            session.setMaxInactiveInterval(3600);

이렇게 @AuthenticationPrincipal 어노테이션을 붙여주면 된다.

OAuth2User 객체는 스프링 컨테이너에 등록되어 있지 않기 때문에 저 어노테이션을 써야한다고 한다

'에러 수정일지' 카테고리의 다른 글

[비동기-0편] 스프링 초기 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. 해결하기  (0) 2025.10.21
'에러 수정일지' 카테고리의 다른 글
  • [비동기-0편] 스프링 초기 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured. 해결하기
Radiata
Radiata
개발을 합니다.
  • Radiata
    DDD
    Radiata
  • 전체
    오늘
    어제
    • 분류 전체보기 (211)
      • 신년사 (3)
        • 2025년 (2)
        • 2026년 (1)
      • CS (59)
        • JVM (12)
        • 백엔드 (20)
        • 언어구현 (1)
        • 객체지향 (1)
        • 논리회로 (5)
        • 컴퓨터구조 (9)
        • 데이터베이스 (1)
        • 컴퓨터 네트워크 (10)
      • 언어공부 (64)
        • Java | Kotlin (48)
        • JavaScript | TypeScript (9)
        • C | C++ (6)
      • 개인 프로젝트 (11)
        • [2025] Happy2SendingMails (3)
        • [2026] 골든리포트! (8)
        • [2026] 순수자바로 개발하기 (0)
        • 기타 이것저것 (0)
      • 팀 프로젝트 (29)
        • [2025][GDG]홍대 맛집 아카이빙 프로젝트 (29)
      • 알고리즘 (13)
        • 백준풀이기록 (11)
      • 놀이터 (0)
      • 에러 수정일지 (2)
      • 고찰 (24)
        • CEOS 23기 회고록 (2)
  • 블로그 메뉴

    • CS
    • 언어공부
    • 개인 프로젝트
    • 팀 프로젝트
    • 알고리즘
    • 고찰
    • 신년사
    • 컬러잇 개발블로그
  • 링크

    • 컬러잇 개발블로그
  • 공지사항

  • 인기 글

  • 태그

    144
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
Radiata
No primary or single unique constructor found for interface org.springframework.security.oauth2.core.user.OAuth2User 해결하기
상단으로

티스토리툴바