Skip to content
This repository was archived by the owner on Apr 9, 2025. It is now read-only.

Latest commit

 

History

History
128 lines (111 loc) · 3.85 KB

task-service-setup.asciidoc

File metadata and controls

128 lines (111 loc) · 3.85 KB

Setup the project

Setup the development environment

We assume you have prepared your environment like described in preparation instruction

Creating the Application

Let’s create a Spring Boot application using the Spring Initializer. Follow these steps to generate your project:

  1. Go to the Spring Initializer website: https://start.spring.io.

  2. Fill out the form with the following details:

    • Project: Maven Project

    • Language: Java

    • Spring Boot: 3.3.4

    • Group: com.capgemini.training

    • Artifact: todo-app

    • Package name: com.capgemini.training.todo

    • Packaging: Jar

    • Java: Select the version corresponding to your JDK installation (21)

  3. Under Dependencies, add the following:

    • Spring Web

    • Lombok

    • H2 Database

    • Spring Data JPA

    • Spring Boot Actuator

    • Flyway Migration

  4. Once all information is filled in, click on the Generate button to download your project.

Here is how your Spring Initializer should look like with the chosen options:

Spring Initializer
  1. Unzip the downloaded project in a convenient location on your system, like C:\trainings\jbf\workspace.

  2. Open terminal, go to the location where you have extracted the sample application and build it using maven

    mvn clean package
  3. Open the project in your preferred IDE.

  4. Explore the project structure. You’ll notice that Spring Initializer has created a basic project setup with the selected dependencies included in the pom.xml file.

Configuring the application

  1. Add following parameters to the application.properties file to enable the H2 Console and configure the H2 data base

    spring.h2.console.enabled=true
    
    spring.datasource.url=jdbc:h2:mem:todoapp
    spring.datasource.username=sa
    spring.datasource.password=password
  2. Add following parameters to the application.properties file to enable more verbosity from the actuator endpoints

    management.endpoint.health.show-components=always
    management.endpoint.health.show-details=always
    management.endpoints.web.exposure.include=*
  3. Add following parameters to the application.properties file to configure the Flyway

    spring.flyway.locations=classpath:db/migration
    spring.flyway.enabled=true
    spring.flyway.clean-on-validation-error=true

Testing the application

  1. Look for the TodoAppApplication.java class and run the application from your IDE. You should see output like this

    ..........
    ... : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:todoapp'
    ..........
    ..........
    ... : Exposing 13 endpoint(s) beneath base path '/actuator'
    ... : Tomcat started on port 8080 (http) with context path ''
    ... : Started TodoAppApplication in 17.632 seconds (process running for 18.605)
    ... : Initializing Spring DispatcherServlet 'dispatcherServlet'
    ... : Initializing Servlet 'dispatcherServlet'
    ... : Completed initialization in 1 ms
  2. Please open the url http://localhost:8080/actuator/health to check whether the application is running correctly. You should get result like this

    Health Endpoint
  3. While implementing the application you will need access to the H2 Database. Open the H2 Console using the following url http://localhost:8080/h2-console/. Please use the correct access data you have configured previously.

    H2 Console - login

    After successful login you should see following content

    H2 Console - content

You’re now ready to start developing your Spring Boot application!