PedroGeoGISdev wiki
  • Home
  • Linux OS
    • Linux: concepts
    • Linux: basic concepts
    • Linux: Bash
    • Linux: su and sudo
    • Linux: pipes
    • Linux: File System
    • Linux: Virtual Machines

    • Linux: distros
    • Linux Distros: Ubuntu
    • Linux Distros: Mint
    • Linux Distros: Debian
    • Linux Distros: openSuse
    • Linux Distros: Manjaro
    • Linux Distros: Red Hat Enterprise

    • Linux: laboratories
    • Linux Lab#LI01-1: Choose Linux
    • Linux Lab#LI01-2: Install at least three distributions
    • Linux Lab#LI01-3: Adjust user permissions
    • Linux Lab#LI02-1: Export env user with grep and pipe
    • Linux Lab#LI03-1: Manage users and groups
    • Linux Lab#LI03-2: Manage files
    • Linux Lab#LI03-3: Manage software
    • Linux Lab#LI03-4: Manage hardware
    • Linux Lab#LI04-1: Bash scripting, qtool
    • Linux Lab#LI04-2: Bash scripts as terminal tool
    • Linux Lab#LI04-3: Distribute the terminal app

    • Linux readings
    • Linux Resources
  • DevOps
    • What is DevOps
    • DevOps: Introduction
    • DevOps: Agile and Microservices
    • Infrastructure as code (IaC)
    • Immutable Infrastructure
    • Software Lifecycle

    • Documentation
    • How to document: Quarto and Obsidian

    • Network protocols
    • Network: Basics
    • Network: Client-server
    • Network Protocols
    • Network: DNS
    • Network: API Rest
    • Network: gRPC
    • Network: Websocket
    • Network: SMTP
    • Network: Ping
    • Network: UDP
    • Network: webhook
    • Network: SOAP
    • Network: graphQL

    • Version Control
    • Git
    • GitHub
    • Idea and GitHub 2023
    • Git and GitHub 2023 CLI

    • IDEs
    • IDE: Visual Code
    • IDE: IntellJIdea

    • DevOps tools
    • Amazon Web Services AWS
    • Docker
    • Jenkins pipelines
    • Kubernetes k8s
    • Digital Ocean
    • Nagios
    • Ansible

    • DevOps Laboratories
    • Lab 1: chat App
    • Lab 2: Spring Boot AWS AEB manually
    • Lab 3: Spring Boot and AWS S3 publisher
    • Lab 4: Spring Boot Docker/Jenkins
    • Lab 5: k8s on Digital Ocean
    • Lab 6: Spring Boot AWS codecommit

    • DevOps readings
    • DevOps Resources
  • MarkUp
    • MarkUp Languages
    • Introduction Markup
    • HTML Markup
    • Markdown Markup
    • Markdown and HTML working together, good idea?

    • Quarto Markdown
    • Quarto Markdown: basics
    • Quarto Markdown: creating
    • Quarto Markdown: publishing
    • Quarto Markdown: code & data
    • Quarto Markdown: api rest call
    • Quarto Markdown: OJS Cells
    • Quarto Markdown: cheat-sheet

    • Styling: CSS
    • Cascade Style Sheet
    • Cascade Style Sheet: Box Model and Containers
    • CSS: W3.css

    • MarkUp Languages Laboratories
    • Lab#MD01-1: Create and publish by Quarto

    • MarkUp Languages readings
    • MarkUp Languages Resources
  • Java SE
    • What is Java SE
    • Java Standard Edition: Basics
    • Java Standard Edition: Principles
    • Java MOOC Helsinki
    • Java MOOC Helsinki Syllabus

    • Java Create Project
    • Java SE: Maven
    • Java SE: Create Maven Project
    • Java SE: Project push GitHub
    • Java SE: JUnit and TDD

    • Java Concepts
    • Java SE: Class and Objects
    • Java SE: Scope
    • Java SE: static modifier
    • Java SE: Coupling and DDD
    • Java SE: Packages
    • Java SE: Abstract/Interface
    • Java SE: Java 8

    • Java Principles
    • Java SE: Encapsulation
    • Java SE: Abstraction
    • Java SE: Inherence
    • Java SE: Polymorphism

    • Java Design Patterns
    • Java Patterns: UML
    • Java Patterns: Types
    • Singleton
    • Factory
    • Abstract Factory
    • Builder
    • Facade
    • Bridge
    • Decorator
    • Composite
    • Observer
    • Strategy
    • State
    • Commander

    • Java SE Laboratories
    • Lab#SE00-1: Maven Person
    • Lab#SE00-2: Maven Clinic
    • Lab#SE00-3: Library Model
    • Lab#SE00-4: Abstract/Interface Human
    • Lab#SE01-1: Maven/Gradle Person and Account
    • Lab#SE01-2: Maven/Gradle Person and Account stored in JSON
    • Lab#SE02-1: Movie/Review, Model
    • Lab#SE02-2: Movie/Review, CRUD Operations
    • Lab#SE02-3: Movie/Review, factory
    • Lab#SE02-4: Movie/Review, interactivity and coupling
    • Lab#SE02-5: Movie/Review, simulate interactivity by console
    • Lab#SE03-1: Library/Book, Core-Model
    • Lab#SE03-2: Library/Book, Sprint Zero
    • Lab#SE03-3: Library/Book, Expand Model
    • Lab#SE04-1: healthyFood Restaurant, Core Model

    • Java SE readings
    • Java SE Resources
  • Python
    • Python Basics
    • Python: Basic Concepts
    • Python: Tips
  • JavaScript
    • JavaScript Basics
    • JavaScript: Basic Concepts
    • JavaScript: Tips
  • Spring
    • Spring Legacy
    • Spring Framework
    • Spring MVC
    • Springs Servlets

    • Spring Boot Basics
    • Spring Boot: fundamentals
    • Spring Boot: create a Project
    • Spring Boot: H2 DB and Thymeleaf
    • Spring Boot: cycle

    • Spring Boot Concepts
    • Spring Boot: Dependency Injection
    • Spring Boot: Annotations
    • Spring Boot: Controller
    • Spring Boot: View
    • Spring Boot: Thymeleaf
    • Spring Boot: Vaadin Flow
    • Spring Boot: Vaadin Hilla
    • Spring Boot: Model
    • Spring Boot: Rest
    • Spring Boot: Data & DB
    • Spring Boot: JPA & DI
    • Spring Boot: JPA Mappings
    • Spring Boot: JPA Relationships
    • Spring Boot: JPA Queries
    • Spring Boot: JPA Inherence
    • Spring Boot: Scaling

    • Spring Boot Laboratories
    • Lab#SB00-1: Library UML
    • Lab#SB00-2: CRUD User
    • Lab#SB00-3: LibraryManagement
    • Lab#SB00-4: API Rest
    • Lab#SB00-5: Rest & JPA-H2
    • Lab#SB00-6: Rest & MongoDB
    • Lab#SB00-7: Styling
    • Lab#SB01-1: DataBase
    • Lab#SB02-1: JPA Relationships
    • Lab#SB03-1: APIs & cloud
    • Lab#SB04-1: JPA Inherence
    • Lab#SB05-1: API Rest
    • Lab#SB06-1: employeeCourse
    • Lab#SB07-1: monitor Book
    • Lab#SB08-1: Restaurant UML
    • Lab#SB08-2: Vaadin
    • Lab#SB08-3: H2 and API Rest
    • Lab#SB08-4: JPA
    • Lab#SB08-5: Test API Rest
    • Lab#SB09-1: SpringIO Conference

    • Spring Boot readings
    • Spring Boot Resources
  • ReactJS
    • ReactJS: Principles
    • React JS: Introduction
    • React JS: render virtual DOM
    • React JS: Create a React project
    • React JS: Components
    • React JS: JSX
    • React JS: props and state

    • JavaScript: web scripting
    • JavaScript: basics
    • JavaScript: functions
    • JavaScript: objects
    • JavaScript: variables
    • JavaScript: flux control

    • ES6: ECMAScript 6
    • React JS ES6: arrow functions
    • React JS ES6: import modules
    • React JS ES6: array, data and key
    • React JS ES6: destructuring
    • React JS ES6: spread operator

    • ReacJS 18: Hooks
    • React JS: Rules of Hooks
    • ReactJS: useState
    • React JS: useReducer
    • React JS: useRef
    • React JS: useEffect
    • React JS: useContext
    • ReactJS: useMemo
    • ReactJS: custom hooks

    • ReactJS: Designing an App
    • React JS App: async
    • React JS App: events
    • React JS App: router
    • React JS App: conditional render
    • React JS App: styling

    • React JS: Laboratories
    • Lab#RE01-1: API Rest Axios
    • Lab#RE02-1: Router & Hooks
    • Lab#RE03-1: to-do app
    • Lab#RE03-2: HighCharts
    • Lab#RE03-3: API Rest Mono
    • Lab#RE03-4: API Rest Domains
    • Lab#RE03-5: data management
    • Lab#RE04-1: todo & server
    • Lab#RE04-2: Spring Boot & ReactJS
    • Lab#RE05-1: chat & websockets
    • Lab#RE05-2: chat: backend
    • Lab#RE05-3: chat & AWS
    • Lab#RE05-4: chat: test ws AWS
    • Lab#RE05-5: chat & front
    • Lab#RE05-6: chat & ws: front
    • Lab#RE06-1: healthyFood Restaurant
    • Lab#RE06-1-PR: create a pull request
    • Lab#RE07-1: traffic lights simulation

    • React JS readings
    • ReactJS Resources
  • Learning
    • Vocabulary
    • General Vocabulary
    • SCRUM Vocabulary
    • DevOps Vocabulary
    • Java SE Vocabulay
    • Spring Boot Vocabulary
    • DataBase Vocabulary
    • ReactJS Vocabulary
    • Web Vocabulary

    • Learning
    • Useful Questions
    • Learning: tips
    • Writing
    • Taking Notes
    • Comments
    • Document
    • Auto-Evaluate

    • Books & Articles
    • Books
    • Articles

    • What is SCRUM
    • SCRUM Agile Methodology
    • Agile Manifesto & Values
    • SCRUM Guide

    • Scrum Steps
    • Meetings, Impediments and Iterations
    • User stories, Tasks and Habits
    • Delivering Value & Communication
    • ScrumMaster, how it works
    • Mindset, the key to everything
    • Product Owner, how it works
    • Managing Time & Mind
    • Team & the Specialist
    • Albertus’ Dilemma
    • Before SCRUM
    • Team Dynamics
    • Emotions and Thoughts
    • Decision Making and Intuition
    • Beyond SCRUM
    • Balances, atmosphere and tools

    • Resources
    • SCRUM Resources
  • QGIS
    • QGIS basics
    • QGIS: basic concepts

    • QGIS laboratories
    • QGIS Laboratory 1: Introduction to Open Source GIS
  • ArcGIS Pro
    • ArcGIS Pro basics
    • ArcGIS Pro: basic concepts

    • ArcGIS Pro laboratories
    • ArcGIS Pro Laboratory 1: Getting Started
  • Bookmarks
    • Online Resources
    • Online Resources
  • About
    • About me and this site
    • About me
    • About this site
    • About images credit
  • Email
  • GitHub
  • LinkedIn
  1. Spring Boot Basics
  2. Spring Boot: H2 DB and Thymeleaf
  • Spring

  • Spring Legacy
    • Spring Framework
    • Spring MVC
    • Springs Servlets

  • Spring Boot Basics
    • Spring Boot: fundamentals
    • Spring Boot: create a Project
    • Spring Boot: H2 DB and Thymeleaf
    • Spring Boot: cycle

  • Spring Boot Concepts
    • Spring Boot: Dependency Injection
    • Spring Boot: Annotations
    • Spring Boot: Controller
    • Spring Boot: View
    • Spring Boot: Thymeleaf
    • Spring Boot: Vaadin Flow
    • Spring Boot: Vaadin Hilla
    • Spring Boot: Model
    • Spring Boot: Rest
    • Spring Boot: Data & DB
    • Spring Boot: JPA & DI
    • Spring Boot: JPA Mappings
    • Spring Boot: JPA Relationships
    • Spring Boot: JPA Queries
    • Spring Boot: JPA Inherence
    • Spring Boot: Scaling

  • Spring Boot Laboratories
    • Lab#SB00-1: Library UML
    • Lab#SB00-2: CRUD User
    • Lab#SB00-3: LibraryManagement
    • Lab#SB00-4: API Rest
    • Lab#SB00-5: Rest & JPA-H2
    • Lab#SB00-6: Rest & MongoDB
    • Lab#SB00-7: Styling

    • Lab#SB01-1: DataBase
    • Lab#SB02-1: JPA Relationships
    • Lab#SB03-1: APIs & cloud
    • Lab#SB04-1: JPA Inherence
    • Lab#SB05-1: API Rest

    • Lab#SB06-1: employeeCourse

    • Lab#SB07-1: monitor Book

    • Lab#SB08-1: Restaurant UML
    • Lab#SB08-2: Vaadin
    • Lab#SB08-3: H2 and API Rest
    • Lab#SB08-4: JPA
    • Lab#SB08-5: Test API Rest

    • Lab#SB09-1: SpringIO Conference

  • Spring Boot readings
    • Spring Boot Resources

On this page

  • 1 Maven Project
    • 1.1 POM.xml and dependencies
  • 2 Model
    • 2.1 @Entity book
    • 2.2 H2 DB creation: step-by-step
    • 2.3 JPA
    • 2.4 Application.Properties
  • 3 Controller
    • 3.1 @Controller Web
  • 4 View: Thymeleaf
  • 5 Example: Library5
    • 5.0.1 Tree-folder Project root
    • 5.0.2 Tree-folder Project
  • 6 Execution
    • 6.1 Auto-reload compiler
  • Edit this page
  • Report an issue
  1. Spring Boot Basics
  2. Spring Boot: H2 DB and Thymeleaf

Spring Boot: H2 DB and Thymeleaf

Spring Boot

Spring-Boot
project
maven
thymeleaf
db
h2
Spring Boot
Author

albertprofe

Published

Tuesday, June 1, 2021

Modified

Sunday, August 10, 2025

📘 Create a Spring Boot Project

  1. Create a Maven Spring Project
  2. Install H2 DB
  3. Define Application.properties
  4. Create Model: @Entity Book and JPA @Repository
  5. Create @Controller and @Service
  6. Create HTML template with Thymeleaf

1 Maven Project

Be careful with this.

Compatibility matrix Java / JPA / ORM Hibernate / Jakarta

Compatibility matrix Java / JPA / ORM Hibernate / Jakarta

1.1 POM.xml and dependencies

Check the base project, Library5.

POM.xml and dependencies: The POM.xml file manages the dependencies of a project in Maven.

  • The first two dependencies, spring-boot-starter-thymeleaf and spring-boot-starter-web, are starter dependencies for Spring Boot and include libraries for building web applications using the Thymeleaf template engine.
  • The spring-boot-devtools dependency provides development-time tools to improve the development experience, such as automatic application restarts and enhanced debugging capabilities.
  • javafaker is a library used to generate random data for testing purposes, and lombok is a library that simplifies Java code by reducing boilerplate code.
  • The spring-boot-starter-test dependency includes the necessary libraries for testing Spring Boot applications, and the junit-jupiter-api dependency provides the JUnit 5 testing framework.
  • The spring-boot-starter-jdbc and spring-boot-starter-data-jpa dependencies provide libraries for accessing and manipulating databases in a Spring Boot application.
  • Finally, the h2 dependency is a lightweight in-memory database used for testing and development purposes.

The groupId and artifactId attributes uniquely identify each dependency, while the version attribute specifies the version of the library to use.

The scope attribute defines the visibility of the dependency at different stages of the application’s lifecycle, and the optional attribute indicates that the dependency is not strictly required for the application to function.

2 Model

2.1 @Entity book

  • Book entity

A persistence entity is a lightweight Java class with its state typically persisted to a table in a relational database.

TipEntity definition
  • Instances of such an entity correspond to individual rows in the table.

  • Entities typically have relationships with other entities, and these relationships are expressed through object/relational mapping (ORM) metadata.

  • This metadata may be specified directly in the entity class file by using annotations (or in a separate XML descriptor file distributed with the application).

DemoApplication.java
@Getter @Setter @NoArgsConstructor @AllArgsConstructor
@Entity(name="Book")
@Table(name="BOOK_TABLE")
public class Book {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="BOOK_ID")
    private long bookId;
    @Column(name="BOOK_TITLE")
    private String title;
    @Column(name="AUTHOR")
    private String author;
    private int pages;
    @Column(name="PUBLISHED_YEAR")
    private int publishedYear;
    @Column(name="ISBN")
    private String isbn;
}
WarningHistorical note

Spring MVC was the original web framework in the Spring ecosystem, and it relied heavily on XML-based configuration.

Over time, Spring MVC evolved to become more annotation-driven, which made it simpler and more concise to work with.

With the advent of Spring Boot, the Spring ecosystem became even more streamlined, with convention-over-configuration and a focus on out-of-the-box features that made it easier to build and deploy Spring-based applications.

In the domian of database access, Spring evolved from using plain JDBC to providing support for Object-Relational Mapping (ORM) frameworks such as Hibernate and JPA.

Spring also provides transaction management capabilities through the Spring Transaction module, which allows developers to define transaction boundaries declaratively using annotations or XML configuration.

By using Spring, developers can build robust, scalable, and maintainable web applications that leverage modern technologies and best practices.

  • Object Relational Mapping (ORM) data access
  • Spring ORM example - JPA, Hibernate, Transaction

2.2 H2 DB creation: step-by-step

  1. Download the H2 database: Go to the H2 database website at H2 DB{external} and download the latest version of the H2 database for Linux. You can download either the ZIP or the TAR package.

  2. Extract the downloaded file: Open the terminal and navigate to the folder where you downloaded the H2 database.Extract the contents of the downloaded file using the following command:

linux.sh
tar -zxvf h2-*.tar.gz
  1. Start the H2 database server: Navigate to the H2 database directory and start the H2 database server by running the following command:
linux.sh
java -jar h2*.jar
linux.sh
cd <download directory>
unzip h2*.zip
cd h2/bin
chmod +x h2.sh

This will start the H2 database server and display the URL where the H2 database can be accessed.

  1. Connect to the H2 database: Open a web browser and enter the URL displayed in the terminal. The H2 database web interface will open in the browser.

    • Other option is to execute the app and then clik “Create a new database” from the H2 Icon

  1. Create a new database: In the H2 database web interface, click on the “Create a new database” button and follow the prompts to create a new database.

Create H2 DataBase: define parameters

Create H2 DataBase: define parameters

Create H2 DataBase: DB created

Create H2 DataBase: DB created

Create H2 DataBase: check it has been created

Create H2 DataBase: check it has been created

Create H2 DataBase: connect to DB

Create H2 DataBase: connect to DB

Name your database: jdbc:h2:/home/albert/MyProjects/MyDBs/h2DBs/myDB

  1. Connect to the new database: Once the new database is created, click on the “Connect” button in the H2 database web interface and introduce the right parameters.
Important

Saved Settings: Generic H2 (Server)
Setting Name: Generic H2 (Server)

Driver Class: org.h2.Driver
JDBC URL: jdbc:h2:/home/albert/MyProjects/MyDBs/h2DBs/myDB

User Name: albert
Password: ••••

Create H2 DataBase

Create H2 DataBase
  1. Use the H2 database: Now you can start using the H2 database. You can create tables, insert data, and perform queries using SQL commands.

2.3 JPA

  • Spring Data JPA - Reference Documentation

JPA: Jakarta Persistence, formerly Java Persistence API

TipJPA definiton

JPA is a application programming interface specification that describes the management of relational data.


DemoApplication.java
public interface BookRepository extends CrudRepository<Book, Long> {}

This code is defining a Java interface named BookRepository that extends the CrudRepository interface.

NoteCrud Repository

The CrudRepository interface is a built-in interface in the Spring Framework that provides generic CRUD (Create, Read, Update, Delete) operations for working with entities in a database.

The BookRepository interface is being used to define a repository for managing Book entities, where Book is likely a Java class representing a book object in the application.

The Long parameter in CrudRepository<Book, Long> specifies the type of the primary key for the Book entity. In this case, the primary key is a Long type.

By extending CrudRepository, the BookRepository interface will inherit methods such as save(), findById(), findAll(), and deleteById(), among others, which can be used to perform database operations on Book entities.

This allows for efficient and standardized data access and management within the application. Otherwise, we should use a DAO:

  • Example DAO MongoDB
  • Example SQL execution in Java

The public keyword specifies that the interface can be accessed from other classes, and the interface name should be in camelCase to follow Java naming conventions.

2.4 Application.Properties

Application.Properties: the application.properties file contains configuration properties for a Spring Boot application.

#H2 DATASOURCE
spring.datasource.url=jdbc:h2:tcp://localhost/~/dataBaseH2/library5
spring.datasource.username=albert
spring.datasource.password=1234
spring.datasource.driver-class-name=org.h2.Driver

#JPA
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect

3 Controller

3.1 @Controller Web

DemoApplication.java
@Controller
@RequestMapping("/library")
public class LibraryWebController {

    @Autowired
    BookService bookService;

    @RequestMapping("/books")
    public String getWeb(Model containerToView) {
        //
        containerToView.addAttribute("booksfromController",
                bookService.getAllBooks());
        

        return "showBooks";
    }
}


The method getWeb() is handling a GET request to the “/library/books” URL path and adding a list of books retrieved from the BookService to the Model attribute “booksfromController”.

@controller and View are connected by HTML/ViewResolver/TH

@controller and View are connected by HTML/ViewResolver/TH

Finally, it returns the name of the view that will be used to render the response.

getWeb method

getWeb method
  1. Java Class and annotations:
    • @Controller: This is an annotation that identifies the class as a Spring MVC controller.
    • @RequestMapping("/library"): This annotation maps the controller to the URL path "/library".
  2. @Autowired BookService bookService;: This annotation injects an instance of the BookService into the controller.
  3. @RequestMapping("/books"): This annotation maps the method to the URL path "/library/books".
  4. public String getWeb(Model containerToView): This is the method declaration for the GET request handler.
  5. containerToView.addAttribute("booksfromController", bookService.getAllBooks());: This adds a list of books retrieved from the BookService to the model attribute "booksfromController".
  6. return "showBooks;: This returns the name of the view that will be used to render the response.

4 View: Thymeleaf

In Spring Boot, the @Controller returns the name of the HTML file (also known as the view) that should be rendered to display the response.

The view is then resolved by the ViewResolver and the corresponding HTML template file is located.

The data that the @Controller wants to send to the view is stored in a Model object. The Model object is passed to the view as a parameter and can be accessed from the HTML template.

TipThymeleaf

Using template engines like Thymeleaf, the view can then use expressions and tags to inject the data from the Model object into the HTML file.

FreeMarker. Apache FreeMarker™ is a template engine: a Java library to generate text output (HTML web pages, e-mails, configuration files, source code, etc.) based on templates and changing data.

Finally, the rendered HTML file with the injected data is sent as the response to the client’s request.

  • showBooks.html on src/mian/resources/templates/

Thyemeleaf builds the HTML table injecting data from Model object. This model objects comes from @Controller.

It builds a <table></table> with a header and multiple rows <tr></tr>

[1] A java forEach wirtten in Thymeleaf iterates over a list of books booksfromController using the trth:each attribute.

NoteScope in Thymeleaf

The th:each attribute on <tr> scope starts in <tr> and finishes in </tr>

[2] For each book, it creates a table cell <td> and displays different attributes of the book, such as bookId, title, isbn, pages, publishedYear, and author.

There are also three links in the row, each represented by an anchor <a> tag.

These links use Thymeleaf’s URL syntax @{...} to generate URLs that invoke Spring MVC @Controller methods.

[3] [4] [5] The deleteBook(), updateBook(), and detailBook() methods will be called with the bookId parameter set to the book.bookId value of the cu Open a web browser and enter the URL dirrent iteration.

The links are styled using CSS classes from the W3.CSS framework.

5 Example: Library5

  • Lab#SB02-Library5 Code
  • Lab#SB02-Library5 Docs

5.0.1 Tree-folder Project root

Collapsed tree-folder:

  1. scr/main: This directory contains two subdirectories - java and resources - which respectively hold the Java source code and resource files for the application.
    • java
    • resources
  2. scr/test: This directory contains unit test code and resources that can be used to test the application.
  3. target and files:
    • target: This directory is the output directory where compiled classes and artifacts are stored.
    • files on root: This directory holds any additional files or resources needed by the application that are not directly related to the code or tests: POM.xml is the most important.

5.0.2 Tree-folder Project

All files in our tree-folder:

The Spring Boot tree-folder structure includes various components such as POM.xml, Git, Java classes, application.properties, and HTML templates that help manage dependencies, version control, database access, configuration, and dynamic content generation.

  1. POM.xml and dependencies: The POM.xml file manages the dependencies of a project in Maven.
  2. Git and .gitignore: Git is a version control system that helps manage code changes, while .gitignore is a file that specifies which files and directories should be excluded from version control.
  3. Main: The main method is the entry point for a Java application, where the program starts execution.
  4. Java Classes:
    • @Entity: A Java class annotated with @Entity is mapped to a database table.
    • @Controller: A Java class annotated with @Controller handles incoming web requests and returns a response.
    • @Repository: A Java class annotated with @Repository provides database access to other classes in the application.
  5. Application.Properties: The application.properties file contains configuration properties for a Spring Boot application.
  6. Templates HTML: HTML templates are used in a web application to generate dynamic content on the server-side.

6 Execution

Web client from Chrome web browser makes a request to Spring Boot Server

Web client from Chrome web browser makes a request to Spring Boot Server

Spring Boot Server gets the request and manages to create a Response to client in HTML file format

Spring Boot Server gets the request and manages to create a Response to client in HTML file format

6.1 Auto-reload compiler

Spring Boot Dev Tools

Any changes to views or resources can be seen in the browser directly, no need restarts, just refresh the browser. As wwll, any changes to the code that will restart the Spring container automatically.

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>

Auto-reload compiler: Advanced Settings

Auto-reload compiler: Advanced Settings

Auto-reload compiler: build project automatically

Auto-reload compiler: build project automatically

Enable this option: compiler.automake.allow.when.app.running

Enable this option: compiler.automake.allow.when.app.running

In Menu -> Build -> Build Project CTRL + F9

Back to top
Spring Boot: create a Project
Spring Boot: cycle

This website is built with Quarto.

Difficulties are just things to overcome, after all. Ernest Shackleton

  • Edit this page
  • Report an issue