スポンサーリンク

javax.servlet.ServletException: No adapter for handler SpringBoot起動時のエラー

2021-02-09 23:36:00.340 ERROR 13512 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [No adapter for handler [com.springhack.happylibrary.controller.bok.BookingController@2b9d51c]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler] with root cause

javax.servlet.ServletException: No adapter for handler [com.springhack.happylibrary.controller.bok.BookingController@2b9d51c]: The DispatcherServlet configuration needs to include a HandlerAdapter that supports this handler
	at org.springframework.web.servlet.DispatcherServlet.getHandlerAdapter(DispatcherServlet.java:1295) ~[spring-webmvc-5.3.3.jar:5.3.3]
 ・・・
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.41.jar:9.0.41]
	at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

解決策

Controller周りのアノテーションの使い方が間違ってないか確認する。

下記の例では、@RestControllerでパス指定してようとしているが、正しくは@RequestMappingで指定するもの。

修正前

@RestController(value= Urls.BOK_01)
public class BookingController {

    @GetMapping
    public String get() {
        return "hoge get";
    }

    @PostMapping
    public String post() {
        return "hoge post";
    }
}

修正後

@RestController
@RequestMapping(value= Urls.BOK_01)
public class BookingController {

    @GetMapping
    public String get() {
        return "hoge get";
    }

    @PostMapping
    public String post() {
        return "hoge post";
    }
}

スポンサーリンク

投稿日:

Copyright© 【Spring Hack】 , 2022 All Rights Reserved Powered by AFFINGER5.