Step 1: Create a Spring application

Create an empty application

Let’s start with backend based on the Spring Framework.

Use the following settings for project generation:

  1. Since we already used Maven in Part 1 and Part 2, we will use it this time as a project builder again.

  2. The language of our backend project is Java.

  3. Use the latest stable version of Spring Boot.

  4. For consistency with the source code examples in this tutorial, set the following project metadata:

    • Group=web.tutorial,

    • Artifact=backend,

    • Name=backend,

    • Description=Supply Chain web service,

    • Package name=web.tutorial.backend.

  5. Use 'Jar' packaging.

  6. The Java version used is 17 (current LTS).

  7. Add 'Spring Web' as the only dependency.

Click "Generate" and download the archive. Unpack the archive with the application on your local disk.

Open the created Spring project

In Eclipse

If you are using Eclipse IDE, choose:

File – Import – Maven – Existing Maven Project

Objects diagram

In the selection window that follows, click “Browse” and select the folder where you unpacked the template project.

Objects diagram

Eclipse will find the pom.xml file. Now you only need to agree by clicking the "Finish" button.

The project should be imported successfully and you should see something like this:

Objects diagram

In IntelliJ IDEA

In IntelliJ IDEA, open the unpacked project using the File – Open menu item:

Objects diagram

Select the pom.xml file of your project. Click OK. Next, select “Open as project”, then “Trust Project".

The project file structure should appear.

"Hello, World"

Let’s create our first controller that responds with the traditional “Hello, World”.

Create a new package web.tutorial.backend.controller. Inside that package, create a new FastExperimentController class:

FastExperimentController.java
package web.tutorial.backend.controller;

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

@RestController
@RequestMapping("/")
public class FastExperimentController {

  @GetMapping(value = "/hello")
  public String hello() {
    return "Hello, World";
  }
}

Check the result

Run the application.

If you are using IntelliJ IDEA, then select Run BackendApplication.class main() in the context menu of the BackendApplication file. If you are using Eclipse, select Run as – Java Application. The application should start.

Now open your browser and enter the address http://localhost:8080/hello. You should see the “Hello, World” string:

Objects diagram