인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

인프런 커뮤니티 질문&답변

황설탕님의 프로필 이미지

작성한 질문수

[개정판 2023-11-27] Spring Boot 3.x 를 이용한 RESTful Web Services 개발

HelloWorld Bean 추가

HelloWorldBean 관련 에러

작성

·

43

·

수정됨

0

`java: constructor HelloWorldBean in class mystudy.myrestfulservice.bean.HelloWorldBean cannot be applied to given types;

required: no arguments

found: java.lang.String

reason: actual and formal argument lists differ in length`

라는 오류 메시지가 자꾸 떠서 강의 진행이 어렵습니다.

package mystudy.myrestfulservice.bean;

import lombok.AllArgsConstructor;
import lombok.Data;

@Data
@AllArgsConstructor
public class HelloWorldBean {

    private String message;
}

 

package mystudy.myrestfulservice.controller;

import mystudy.myrestfulservice.bean.HelloWorldBean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorldController {

    // GET
    // URI - /hello-world
    // @RequestMapping(method = RequestMethod.GET , path = "/hello-world")

    @GetMapping(path = "/hello-world")
    public String helloWorld() {
        return "Hello World!";
    }

    @GetMapping(path = "/hello-world-bean")
    public HelloWorldBean helloWorldBean() {
        return new HelloWorldBean("Hello World");
    }

    @GetMapping(path = "/hello-world-bean/path-variable/{name}")
    public HelloWorldBean helloWorldBeanPathVariable(@PathVariable String name) {
        return new HelloWorldBean(String.format("Hello World %s", name));
    }
}

Enable Annotation Processing 체크하기 ,리빌드, 캐시 삭제, 재부팅, 롬복 재설치, 프로젝트 다시 생성하기 별에 별 방법을 써도 안됩니다...

답변 1

0

인프런 AI 인턴님의 프로필 이미지

안녕하세요, 인프런 AI 인턴입니다. 황설탕님께서 겪고 계신 오류는 HelloWorldBean 클래스의 생성자와 관련된 문제입니다. 해당 오류 메시지는 컴파일러가 HelloWorldBean 인스턴스를 생성할 때, 매개변수의 타입과 개수가 클래스에 정의된 생성자와 일치하지 않다는 것을 의미합니다.

@AllArgsConstructor 어노테이션은 클래스의 모든 필드를 매개변수로 가지는 생성자를 자동으로 생성해주는 롬복 어노테이션입니다. 하지만 지금 바로 오류가 나타나는 이유는 반복적인 캐시 문제 때문일 수 있습니다.

다음과 같은 해결책이 있습니다:

  1. 롬복 설정 확인: 롬복이 제대로 동작하지 않는 경우가 가끔 있으므로, 롬복이 제대로 작동하고 있는지 확인해보세요. 프로젝트의 pom.xml이나 build.gradle 파일의 롬복 의존성을 재확인 해보세요.

  2. IDE 설정: IntelliJ IDEA나 Eclipse를 사용하신다면 롬복 플러그인이 설치되었고, 활성화되어 있는지 다시 확인해주십시오.

  3. 클린 빌드: mvn clean install이나 gradle clean build 명령어로 클린 빌드를 다시 시도해 보세요.

  4. 캐시 삭제: IDE의 캐시 삭제와 재시작을 통해 롬복에 대한 컴파일 문제를 해결할 수 있습니다. 이미 시도해보셨다면, 다른 방법으로 Maven이나 Gradle의 의존성 캐시를 지우고 다시 빌드해 보시기 바랍니다.

질문 내용과 비슷한 상황에 대한 다른 질문과 답변이 아래 링크에서 논의되었습니다:

이 답변이 질문자님의 문제 해결에 도움이 되기를 바랍니다.

저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해 드리고 있습니다.
현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏
추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.