Spring Boot Controller not mapping

前端 未结 9 1474
慢半拍i
慢半拍i 2021-02-05 02:55

I have used STS and now I am using IntelliJ Ultimate Edition but I am still getting the same output. My controller is not getting mapped thus showing 404 error. I am completely

相关标签:
9条回答
  • 2021-02-05 03:14

    It depends on a couple of properties:

    • server.contextPath property in application properties. If it's set to any value then you need to append that in your request url. If there is no such property then add this line in application.properties server.contextPath=/
    • method property in @RequestMapping, there does not seem to be any value and hence, as per documentation, it should map to all the methods. However, if you want it to listen to any particular method then you can set it to let's say method = HttpMethod.GET
    0 讨论(0)
  • 2021-02-05 03:28

    Because of DemoApplication.class and HelloController.class in the same package
    Locate your main application class in a root package above other classes
    Take look at Spring Boot documentation Locating the Main Application Class

    Using a root package also allows component scan to apply only on your project.

    For example, in your case it looks like below:

    com.webservice.demo.DemoApplication
    com.webservice.demo.controller.HelloController

    0 讨论(0)
  • 2021-02-05 03:28

    In my case I used wrong port for test request - Tomcat was started with several ones exposed (including one for monitoring /actuator).

    0 讨论(0)
提交回复
热议问题