-
[error] Name for argument of type [java.lang.Long] not specifiedT-note 2024. 1. 9. 15:17728x90
발생한 에러
Name for argument of type [java.lang.Long] not specified, and parameter name information not found in class file either
parameter에 @PathVariable을 사용했을때 명시되어 있는 이름이 없어서 나오는 에러이다.
해결 방법
구글링을 해보면, 나오는 해결 방법은 아래와 같다.
1. gradle에 추가해보기
compileJava { options.compilerArgs << '-parameters'}
2. 인텔리제이 > 설정 > 빌드, 실행, 배포 > 컴파일러 > 자바 컴파일러
위와 같이 해당 명령어를 추가하기
3. 파라미터에 이름을 정확하게 명시하기
-> 나의 경우에는 이 방법으로 되었다.
기존 코드
@PatchMapping("/{scheduleId}") public ResponseEntity<Result> updateSchedule(@RequestBody ScheduleRequestDto dto, @PathVariable Long scheduleId, @AuthenticationPrincipal PrincipalDetails user) { ScheduleResponseDto response = scheduleService.updateSchedule(dto, scheduleId, user); return ResponseEntity.ok(Result.of(response)); }
해결한 코드
@PatchMapping("/{scheduleId}") public ResponseEntity<Result> updateSchedule(@RequestBody ScheduleRequestDto dto, @PathVariable("scheduleId") Long scheduleId, @AuthenticationPrincipal PrincipalDetails user) { ScheduleResponseDto response = scheduleService.updateSchedule(dto, scheduleId, user); return ResponseEntity.ok(Result.of(response)); }
이렇게 PathVariable에 명확하게 이름을 주웠다.
'T-note' 카테고리의 다른 글
[code deploy] code deploy중 access denied (2) 2024.02.16 [Tnote] error: variable userRepository not initialized in the default constructor (0) 2024.02.15 [error] build 오류 (0) 2024.02.10 [Tnote] 스프링 시큐리티 - @AuthenticationPrincipal 로그인 정보 받기 (0) 2023.12.30 [Tnote] security 버전 변경에 따른 설정 변경 (2) 2023.12.28