Getting “No message available” error with Spring Boot + REST application

后端 未结 10 2404
感动是毒
感动是毒 2020-12-30 02:02

I have created demo Spring Boot project and implemented Restful services as shown here

@RestController
public class GreetingsController {
    @RequestMappin         


        
相关标签:
10条回答
  • 2020-12-30 02:26

    If you are using @SpringBootApplication alone, then make sure your rest service controller is in the same package like below -

    com.testSpring->SpringBootApplication class
    com.testSpring.controller->RestfulController classes
    com.testSpring.model->Model classes
    ..etc
    

    If you are using @ComponentScan(basePackageClasses = UserController.class), then mention specific controller class names.

    0 讨论(0)
  • 2020-12-30 02:33

    For me I have the same error, but I realise that the path I put to call the api is the problem. If my application name is demo, I have to call http://localhost:9090/AdminProducts to access AdminProducts, not http://localhost:9090/demo/AdminProducts. This name may be use after deploying the war in tomcat.

    0 讨论(0)
  • 2020-12-30 02:34

    This can help someone as it was in my case.

    Make sure the package name of the controller is the derived (or child) package of your Spring main method package.

    For example:

    If the main method package is com.company.demo.example then the controller package should be like com.company.demo.example.controller (if you specify something like com.company.demo.controller it won't work!).

    0 讨论(0)
  • 2020-12-30 02:43

    all your packages should be after the main package,

    like this com.example.demo.* (all your packages)

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