Web Programming/Spring
Spring Request Mapping 매개변수 오류
럼포
2024. 12. 20. 13:37
문제상황
put request를 진행 중 다음과 같은 오류가 떴다.
java.lang.IllegalArgumentException: Name for argument of type [java.lang.Integer] not specified, and parameter name information not available via reflection. Ensure that the compiler uses the '-parameters' flag.
해결방법
1. compiler옵션에 -parameters 추가
(intellij) 사용 시
File -> settings -> Build, Execution, Deployment → Compiler → Java Compiler 에서 Additional command line parameters에 다음 항목 추가
- parameters
프로젝트 폴더 중 out 폴더를 삭제하고 다시 실행(out 폴더를 삭제해야 다시 컴파일 된다고 함.)
2. 파라미터 이름을 명확하게 명시
@PutMapping("/{postId}")
public void updatePost(@PathVariable("postId") Integer postId, @RequestBody Post post){
postService.update(postId, post);
}
@PathVariable에 전달하고자 하는 파라미터 이름을 지정해준다.
참고: