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

后端 未结 10 2477
感动是毒
感动是毒 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:17

    Apart from the anotatting the SpringBoot entry point with @SpringBootApplication((scanBasePackages = "com.duwamish.x.y") so that it includes all the spring components/beans when initialized,

    The contextPath also has to be right. If the application is deployed to tomcat with the application name as myapplication see below,

    $ ll /usr/local/apache-tomcat-8.0.42/webapps/
    total 179216
    12495017 drwxrwxrwx  17 urayagppd  NORD\Domain Users       578 Mar  8 11:59 ROOT
    12495019 drwxrwxrwx  55 urayagppd  NORD\Domain Users      1870 Mar  8 11:59 docs
    12495042 drwxrwxrwx   7 urayagppd  NORD\Domain Users       238 Mar  8 11:59 examples
    12495109 drwxrwxrwx   7 urayagppd  NORD\Domain Users       238 Mar  8 11:59 host-manager
    12495114 drwxrwxrwx   8 urayagppd  NORD\Domain Users       272 Mar  8 11:59 manager
    16169612 drwxr-xr-x   4 urayagppd  NORD\Domain Users       136 May  7 18:47 myapplication
    16169594 -rw-r--r--   1 urayagppd  NORD\Domain Users  45340041 May  7 18:47 myapplication.war
    

    Then REST endpoint would be /myapplication/api/greetings

    But if the application war is deployed as ROOT, the endpoint resource will be /api/greetings only.

提交回复
热议问题