Your First Spring Boot Application in Minutes
Your First Spring Boot Application in Minutes
The fastest way to start is Spring Initializr, either at start.spring.io or inside your IDE. You pick the build tool - Maven or Gradle - the language, and the dependencies you want, then download a ready-to-run project. For a first app, choose the Spring Web dependency.
The main class
Boot applications are plain Java programs. One class carries the @SpringBootApplication annotation and a main method that calls SpringApplication.run. That single annotation combines component scanning, configuration, and auto-configuration into one entry point.
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
Add a controller and run
Right now the app starts but returns 404 for everything. Add a controller and a mapping so it serves a response.
@RestController
public class HelloController {
@GetMapping("/")
public String hello() {
return "Hello, GroovyGrails!";
}
}
Run mvn spring-boot:run or launch the main method from your IDE. Boot starts an embedded Tomcat, you see the log line about Tomcat started on port 8080, and opening http://localhost:8080 returns your message.
DevTools and reload
Add spring-boot-devtools to get automatic restarts when code changes, live reload in the browser, and faster iteration. It is disabled automatically when you package the app for production.
First things to try
Change the server port with server.port=9090 in application.properties, then switch the message to read from configuration. You now have the skeleton for everything this tutorial covers.
Key Points
- Use Spring Initializr to scaffold a project with the dependencies you need.
@SpringBootApplicationbundles scanning, configuration, and auto-configuration.- Embedded Tomcat starts with the app; run via Maven or the main method.
- Add
spring-boot-devtoolsfor reloads during development. - Overrides like
server.portlive inapplication.properties.