With Spring Initializr you can bootstrap a new Spring Boot application swiftly. Let’s create a fresh project from scratch using just Web and MySQL dependencies.
What we are going to build
We will bootstrap a fresh project with basic dependencies required for a web application.
You will need Java SDK v1.8 or higher. If this is your first java project, install Java Development Kit:
To check which version is installed on your computer, run:
This tutorial’s project is created on Kubuntu – remember to adjust commands if you don’t work on Linux OS.
Setting up the project
Spring Initializr provides a simple web UI allowing you to customize the project, specify its dependencies and download an already bootstrapped application.
Visit start.spring.io/, insert :
- the name of the project’s
Group– usually it is the inversed domain of your company and is used as a default root package of the app;
- project’s name into the
Artifactfield – if the name of your project is
my-app, the generated project will have a
MyAppApplication.javaclass with a
main()method to bootstrap the application;
Descriptionof the application.
If you won’t specify
Package Name, the value of the
Group attribute is used for the root package of the project. In our case, the path to the class with a main() method will look like this:
MySQL dependencies, place the cursor in the
Search for dependencies field, start typing those names and pick out the packages from the list of matching choices.
You can also explore advanced options of Spring Initializr by clicking the Switch to the full version link below the
Generate Project button.
Generate the project and save the zip file on your machine. Go to your project location and unzip the file:
To see the structure of the downloaded demo go to the project directory and list the application files:
To finally test the project installation, create a simple controller displaying a greeting message:
You need to debug and run the application. If you chose
awesome-project as the name of your application in Spring Initializr, go to
AwesomeProjectApplication.java, click the green arrow on the left of the class declaration and select
Debug 'AwesomeProject...main()' option:
You should get the console output with the Tomcat port, mine is:
http://localhost:8080/ in your browser and check for the LandingPageController output: Welcome on the landing page!
You should now store your project in a git repository. Check out this tutorial on starting with git.