Running Your First App
Running your first app starts it so a browser can visit it. A browser visit is a request, and the app answers it.
Start the app
This command runs the app. Run it in the project folder.
mvn spring-boot:runAsk the app
This command asks the app for its answer at /hello.
curl http://localhost:8080/helloExample
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}Key points
- Spring Boot runs the app with one Maven command.
- The command runs in a terminal, in the project folder.
- The app starts on port 8080.
- A port is a number that marks where the app listens.
- Localhost means this computer.
- A visit to /hello asks the app for its answer.
In this example, the app class is the start of the app. The main method hands the app class to Spring. The app runs on port 8080. A request to /hello returns the text Hello, Spring Boot! The next lesson shows the small class that answers it.
Note
Stop the app with CTRL+C in the terminal.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Which command runs the app?