source

DispatcherServlet 구성에는 이 핸들러를 지원하는 HandlerAdapter가 포함되어야 합니다.

ittop 2023. 7. 21. 21:55
반응형

DispatcherServlet 구성에는 이 핸들러를 지원하는 HandlerAdapter가 포함되어야 합니다.

저는 rest api를 설계하려고 하는데, 아래는 제 컨트롤러 코드입니다.

http://localhost:8080/호출할 때 응답은 정상이지만 http://localhost:8080/api/caitthrows를 누르면javax.servlet.ServletException: No adapter for handler [...CaDetailController@48224381]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler

@RestController("/api")
public class CaDetailController {

    private static final Logger logger = LoggerFactory.getLogger(GetClassLoader.class.getClass());

    @Autowired
    CaService caService;

    @RequestMapping(path = "/ca", method = RequestMethod.GET)
    public @ResponseBody List<CaDetail> getCorporateActions() {
        logger.info("CaDetailController.findAllCaDetails()");
        return caService.findAllCaDetails();
    }

    @RequestMapping(path = "/ca/{caId}", method = RequestMethod.GET)
    public @ResponseBody List<CaDetail> getCorporateActions(@PathParam("caId") long caId) {
        logger.info("CaDetailController.getCorporateActions() : caId : " + caId);
        return caService.findAllCaDetails();
    }
}

컨트롤러가 업데이트되었습니다.

@RestController
@RequestMapping("/api/ca")
public class CaDetailController {

    private static final Logger logger = LoggerFactory.getLogger(GetClassLoader.class.getClass());

    @Autowired
    CaService caService;

    @GetMapping(path = "/")
    public @ResponseBody List<CaDetail> getCorporateActions() {
        logger.info("CaDetailController.findAllCaDetails()");
        return caService.findAllCaDetails();
    }

    @GetMapping(path = "/{caId}")
    public @ResponseBody List<CaDetail> getCorporateActions(@PathParam("caId") Long caId) {
        logger.info("CaDetailController.getCorporateActions() : caId : " + caId);
        return caService.findAllCaDetails();
    }
}

명확한 설명을 위해 수정 사항은 다음과 같습니다.

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/api/ca")
public class CaDetailController {

    @GetMapping
    public String healthcheck1() {
        return "ok!";
    }

    @GetMapping(path = "health")
    public String healthcheck2() {
        return "ok again!";
    }

}

URL: http://localhost:8080/api/ca 및 http://localhost:8080/api/ca/health를 사용하여 이 끝점을 호출할 수 있습니다.

(기본 Spring Boot Tomcat 구성으로 가정).

("/api") 값을 @RestController Annotation에 추가하지 않고 @RequestMapping에 추가합니다.

@RestController
@RequestMapping("api/")
...

사용해 보세요.

@RestController
@RequestMapping("/api")
public class CaDetailController {

대신에

@RestController("/api")
public class CaDetailController {

언급URL : https://stackoverflow.com/questions/54802028/dispatcherservlet-configuration-needs-to-include-a-handleradapter-that-supports

반응형