Unresolved reference: web

Kotlin과 Spring Boot에서 Unresolved reference: web 오류를 Gradle 의존성 설정으로 해결하는 방법.

Kotlin, Spring Boot, Gradle, Backend

Kotlin Spring Boot Gradle Unresolved reference: web song for the mute Jun 10, 2024

Kotlin, Gradle을 이용한 Spring Boot 애플리케이션을 구성하며 발생한 오류다.

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

컨트롤러 어노테이션으로 클래스를 선언하고자 하였으나, 해당 모듈을 import 하는 부분에서 web 모듈의 참조를 찾지 못해 발생하는 것으로 보였다.

RestController, GetMapping 어노테이션과 같은 Spring Boot의 웹 기능을 이용하려면 spring-boot-starter-web 종속성이 필요한데, build.gradle.kts 파일에 종속성이 누락되어 발생한 것이었다.

implementation("org.springframework.boot:spring-boot-starter-web")

build.gradle.kts 파일의 종속성 목록에 다음의 코드를 추가하고 Gradle 프로젝트를 동기화하면 위의 참조 오류를 해결하고 정상적으로 모듈을 import 할 수 있다.

https://start.spring.io

이외에도 start.spring.io에서 Spring Boot 프로젝트를 생성할 때, Spring Web 종속성을 추가해서 생성한다면 위와 같이 spring-boot-starter-web 종속성의 누락을 막을 수 있다.

References

https://start.spring.io MacOS 12.6 Monterey Intellij IDEA CE 2023.02 Azul Zulu 17.0 JDK


원문: Medium