Spring Boot: Cannot access REST Controller on localhost (404)

前端 未结 18 1488
天命终不由人
天命终不由人 2020-11-27 12:05

I am trying to adapt the REST Controller example on the Spring Boot website. Unfortunately I\'ve got the following error when I am trying to access the localhost:8080/

18条回答
  •  独厮守ぢ
    2020-11-27 12:27

    There are 2 method to overcome this

    1. Place the bootup application at start of the package structure and rest all controller inside it.

      Example :

      package com.spring.boot.app; - You bootup application(i.e. Main Method -SpringApplication.run(App.class, args);)

      You Rest Controller in with the same package structure Example : package com.spring.boot.app.rest;

    2. Explicitly define the Controller in the Bootup package.

    Method 1 is more cleaner.

提交回复
热议问题