spring-bootspring-initializr

A new project using Spring Initializr does not run in browser


Building a new project downloaded using https://start.spring.io/ does not run on browser. I have seen some solutions on stackoverflow which require to make some changes or add, but default/out-of-the-box application does not run.

I asked this in Github https://github.com/spring-projects/spring-boot/issues/20603 but was told that i need to add request mappings or something else. There's no default mapping for the root. That's indeed the default error page showing you a 404.

Is there a documentation to "add request mappings or something else" ? It will help if the application run showing some text instead of an error message. This maybe a simple obvious thing for Spring developers but for learners, takes a lot of effort.

http://localhost:8080/

enter image description here

STEPS TO REPRODUCE:

Download new project at https://start.spring.io/

enter image description here

mvn clean package

enter image description here

mvn spring-boot:run

enter image description here


Solution

  • That is the expected behavior right after creating a fresh Spring Boot project. The initializer does not register any endpoint for you, it just gives you the project skeleton you can start working with.

    If you want to see something on localhost:8080/ consider adding the following Java class to your project:

    @RestController
    public class HelloWorldController {
    
      @GetMapping
      public String helloWorld() {
        return "Hello World!";
      }
    
    }
    

    If you are new to Spring/Spring Boot, I can recommend the following resources: