코딩 관련/Java
java.lang.IllegalArgumentException: Name for argument of type [java.lang.String] not specified, and parameter name information not found in class file either. 원인
메리짱123
2023. 12. 27. 13:42
반응형
버전 : 자바17
내 컨트롤러 메소드..
@GetMapping(value = "/info/{a1}")
public void getInfo(@PathVariable String a1) throws Exception {
}
이 api를 호출하면 아래와 같은 에러가 나는 것이었다
java.lang.IllegalArgumentException: Name for argument of type [java.lang.String] not specified, and parameter name information not found in class file either.
path parameter와 변수명이 같으면 name을 명시 안 해줘도 되는걸로 알고있었는데
컴파일 모드가 debug 모드가 아닌 경우 컴파일 시 로컬 지역변수가 포함이 안 되어 변수 맵핑을 못 한다고 함.
컨트롤러 메소드에 name옵션 추가해줌..
@GetMapping(value = "/info/{a1}")
public void getInfo(@PathVariable(name="a1") String a1) throws Exception {
}
아니면 컴파일 시 지역변수 포함하도록 build.gradle 파일을 손봐준다.
셋중에 하나 추가
java {
options.compilerArgs << "-g"
}
tasks.withType(JavaCompile) {
options.compilerArgs.add("-parameters")
}
compileJava {
options.compilerArgs << '-parameters'
}
반응형