How To Create Spring Boot Project using Spring Starter Kit

How To Create Spring Boot Project using Spring Starter Kit

You can bootstrap the Spring Boot application with one of the two methods available.

  1. Spring starter kit.
  2. IntelliJ Idea

In either of the two methods, you will see two sections in columns, one is for the project metadata, and the other is for adding dependencies for your Spring boot project.

Adding dependencies can be done later after generating the project as well. But it's easy to add a dependency by choosing from a huge list.

1. Spring Starter kit

Go to https://start.spring.io/, and you will be given a form to fill in the metadata of your spring project.

https://start.spring.io

Steps:

  1. Select the Maven or Gradle project based on your preferences.
  2. Choose Java as your language and SpringBoot version as the latest stable release.
  3. For the project metadata, change the following.
    1. Group: dev.ggorantala
    2. Artifact: Lowercase recommended. For simplicity, this is already set to demo.
    3. Name: Leave it to defaults.
    4. Description: You can change it or leave it. This is an optional field.
    5. Package Name: Let it be jar for now.
    6. Java Version: Select the java language installed on your machine. Choose the LTS version.
  4. Dependencies: We can add single or multiple dependencies here based on our choice. Let's try to bring up something on the webpage. To do this, we need to add Spring Web as a dependency.

Spring Web: This dependency helps build web, including RESTful, Spring MVC and, interestingly, the Spring Web dependency has an embedded Tomcat container.

Click on Generate to generate the configured project. Download, unzip, and open it with your IDE (IntelliJ Idea / Eclipse / STS).

Grab Your Free IntelliJ Idea/JetBrains License 🤩
Jetbrains offers free licenses for most of the categories. Get all of the below tools for free from JetBrains Here is a set of lists qualifying for a free ultimate JetBrains pack with unlimited access to features. 🤑 Free for who? 1. Students, teachers and Educators. 2. Open Source Contributor…

2. Using IntelliJ Idea

IntelliJ Idea is the number one choice, per the survey conducted by open Java communities and the Java official channel.

For instance, I was asked to only use IntelliJ Idea when I worked for Apple, Jive SBS, a Medical startup and European Commission companies.

Spring Boot project starter kit

Steps:

  1. Install IntelliJ Idea. Could you open it and click on New Project?
  2. For the project metadata, change the following.
    1. Name: Leave it to defaults.
    2. Language: Select Java.
    3. Type: Select Maven
    4. Group: dev.ggorantala. You can choose your own.
    5. Artifact: Lowercase recommended. For simplicity, this is already set to demo.
    6. Description: You can change it or leave it. This is an optional field.
    7. Package Name: Let it be jar for now.
    8. JDK Version: Select the java language installed on your machine. Choose the LTS version. I use Java 17 to get a load of all the advanced features.

Click next, and you will see the following screen.

Spring Boot project dependencies

We can add single or multiple dependencies here based on our choice. Let's try to bring up something on the webpage. To do this, we need to add Spring Web as a dependency. Search for Spring Web

Spring Web: This dependency helps build web, including RESTful, Spring MVC and, interestingly, the Spring Web dependency has an embedded Tomcat container.

Once either of the above steps to you to download the project. Open with your favourite IDE and start/run the project. We started the project, and a snapshot is copied below.

Spring Boot project

After starting the project, we saw a built Tomcat runs our application.

2022-11-17 09:44:58.103  INFO 3039 --- [main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.68]
2022-11-17 09:44:58.138  INFO 3039 --- [main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-11-17 09:44:58.138  INFO 3039 --- [main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 395 ms
2022-11-17 09:44:58.278  INFO 3039 --- [main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-11-17 09:44:58.284  INFO 3039 --- [main] dev.ggorantala.demo.DemoApplication      : Started DemoApplication in 0.775 seconds (JVM running for 1.006)

Navigate to https://localhost:8080, or the IP address of the localhost is "127.0.0.1".

To access either https://localhost:8080 or  https://127.0.0.1:8080  to see your application live.

Don't be surprised to see the following error screenshot when you access   https://127.0.0.1:8080. If you see the following error, then we are good.

Spring lets you know that the application is up and running. Needs configuration!!

Add the following code to the project we created, and we can see our first greeting message live on the webpage.

package dev.ggorantala.demo.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HomeController {

    @GetMapping("/")
    public String greetHello() {
        return "Hey there, congratulations in building your first project!!";
    }

}

Snapshot:

String message returned on the root

Isn't this the simplest configuration and bootstrapping an application from scratch?

🤩 Happy Coding!!