How to create a new Spring Boot Project

feature image

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.

Requirements

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:

You will be coding in an integrated development environment. Choose the one that supports Java8, JavaScript, HTML, is compatible with Git and enables you to build, debug, and run tests with ease.  For the IDE I recommend IntelliJ IDEA Community Edition, but you can choose Eclipse, Netbeans or whichever you like.

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  Artifact field – if the name of your project is my-app, the generated project will have a MyAppApplication.java class with a main() method to bootstrap the application;
  • short Description of 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:

awesome-project/src/main/java/in/keepgrowing/awesomeproject/AwesomeProjectApplication.java

To select Web and 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.

Screenshot of Spring Initializr with example project data
Spring Initializr with example project data

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:

Screenshot of AwesomeProjectApplication.java class
AwesomeProjectApplication.java class

You should get the console output with the Tomcat port, mine is:

Visit 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.

Photo by Nick Scheerbart on StockSnap

Leave a Reply

Your email address will not be published. Required fields are marked *