spring-guides / gs-rest-service

Building a RESTful Web Service :: Learn how to create a RESTful web service with Spring.

Home Page:https://spring.io/guides/gs/rest-service/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rest Service guide is missing source code for RestServiceApplication.java

cybersteel8 opened this issue · comments

https://spring.io/guides/gs/rest-service/

This page contains the source code to build this application from scratch, however at the section where @SpringBootApplication is mentioned, there is no associated source code. I had to come here to find it.

do you want to see code below in documentation?

package com.example.restservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class RestServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(RestServiceApplication.class, args);
    }

}


I was also confused about the @SpringBootApplication part of the guide as well what to do with the DemoApplication.java that came included with the Spring Initializr download. I think adding the following steps to the official guide on the site would be helpful for beginners:

  1. Create a new file called src/main/java/com/example/restservice/RestServiceApplication.java
  2. Add code mentioned by @boraoren above.
  3. Delete src/main/java/com/example/demo/DemoApplication.java

Yea this can easily be confusing for people that are just getting into Spring.

Yeah, all 3 classes (DemoApplication, Greeting and GreetingController) should be in the same package (either com/example/demo or com/example/restservice, like the tutorial says) or else localhost:8080/greeting returns an error page.