Hello World
This guide walks you through the process of creating a “Hello, World” web site with Spring.
What You Will Build
You will build an application that has a static home page and that will also accept HTTP GET requests at:
http://localhost:8080/greeting
.
It will respond with a web page that displays HTML. The body of the HTML will contain a greeting: “Hello, World!”
You can customize the greeting with an optional
name
parameter in the query string. The URL might then be http://localhost:8080/greeting?name=User
.
The
name
parameter value overrides the default value of World
and is reflected in the response by the content changing to “Hello, User!”
What You Need
- About 15 minutes
- A favorite text editor or IDE
- JDK 1.8 or later
- Gradle 4+ or Maven 3.2+
- You can also import the code straight into your IDE:
How to complete this guide
Like most Spring Getting Started guides, you can start from scratch and complete each step or you can bypass basic setup steps that are already familiar to you. Either way, you end up with working code.
To start from scratch, move on to Starting with Spring Initializr.
To skip the basics, do the following:
- Download and unzip the source repository for this guide, or clone it using Git:
git clone https://github.com/spring-guides/gs-serving-web-content.git
- cd into
gs-serving-web-content/initial
- Jump ahead to Create a Web Controller.
When you finish, you can check your results against the code in
gs-serving-web-content/complete
.