DEV Community

Kathir
Kathir

Posted on

Spring Boot Notes — Day 1 | My Learning Notes from the Spring Boot Documentation

Note: I am currently going through the Spring Boot documentation and documenting my learning journey. These are my Day 1 notes. I have organized my notes into a blog format without changing the concepts or content.


What is Spring?

Spring is a Java framework. Provides features like Dependency Injection (IoC), MVC, Security, Data Access, REST APIs, Transactions, AOP (Aspect Oriented Programming).

Spring is very powerful but it requires lot of configurations like configure DispatcherServlet, Tomcat, XML, Beans, Database, Properties, Jackson, Logging, Context.

Developers spent more time configuring the configurations than coding. So, the spring team developed Spring Boot.

Spring = Powerful Engine

Spring Boot = Spring + Automation + Defaults
Enter fullscreen mode Exit fullscreen mode

Boot doesn't replace Spring. It sits on tops of Spring.

Spring Boot doesn't create application for you. It is an assistant and you still write the code but removes repetitive works.


Stand-alone Application

With Spring Boot you can build stand-alone application.

Stand-alone application = Before Spring Boot, You had to install Tomcat, Jetty, WildFly, GlassFish and then deploy .war into the server.

You depended on external server but stand-along application do have everything it needs inside it.

Example:

myapp.jar

├── Application code
├── Spring
├── Tomcat
├── Libraries
├── Configurations
└── Dependencies
Enter fullscreen mode Exit fullscreen mode

myapp.jar contains Application code, Spring, Tomcat, Libraries, Configurations, Dependencies.


Production Grade Application

It helps to build production grade application.

(Application suitable for running at real-time environment).

Production application need:

  • Security
  • Monitoring
  • Logging
  • Error Handling
  • Health Checks
  • Metrics
  • External Configuration
  • Performance
  • Scalability

Logging

Logging- It means recording what your application is doing from start to end.

These recording messages is called logs.

Without logging, You wouldn't know if something went wrong.

Logback is the default logging implementation used by Spring Boot since it is fast, reliable, easy configuration and well integrated with SLF4J.

Other logging framework:

  • Log4j

SLF4J

SLF4J = Simple Logging Facade For Java.

It is not a logging implementation but a common interface.

Code uses SLF4J and it forwards logging calls to the actual logging framework.


Database Connection Pool

Database Connection Pool = It is a collection of pre-created database connections that remain available while the application is running, so they can be reused instead of creating a new connection for every database request.

Some connection pool are:

  • Hikari
  • C3P0
  • DBCP

HikariCP

HikariCP = It is a high performance connection pool.

Spring Boot prefers it since it is very fast, low memory usage, excellent performance under heavy load and have simple configuration.


JSON

JSON stands for JavaScript Object Notation.

It is the standard format for exchanging data between systems.

JSON libraries:

Jackson

  • It converts Objects to JSON.
  • Json back to java objects automatically.

Gson

  • Created by Google.
  • Also converts objects to JSON.

JSON-B

JSON binding.

It is a java standard unlike jackson which not java standard api but a third party library.


Embedded Server

Embedded Server => It is a web server that is packaged inside your application and starts automatically when your application starts.

You don't have to manually install or configure a separate web server.

Spring Boot default uses Tomcat as an embedded server becuase it is mature, stable and widely used but you can replace it with:

Jetty

Known for beging light weight and embeddable.

Undertow

A high performance web server forcused on speed and low resource usage.


Metrics

Metric = Micrometer is the mertics library use by spring boot.

It collects information different parts of the application.


Spring Boot Defaults

Spring Boot uses Defaults but you can also change them by your configurations.


Spring Platform

It is a Spring Ecosystem.

The Spring platform is the broader colllection of Spring projects built around the Spring framework.

It includes:

  • Spring Framework (core)
  • Spring Boot
  • Spring Data
  • Spring Security
  • Spring cloud-microservices
  • Spring Batch- batch processing
  • Spring Integration-enterprise integration
  • Spring WebFlux-reactive web applications
  • Spring AOP
  • Spring JDBC
  • Spring ORM

Simple Analogy

Think of a smartphone:

Android OS = Spring Framework

Android ecosystem
(Playstore, Maps, Gmail, etc.)
        =
Spring Platform
Enter fullscreen mode Exit fullscreen mode

Boot is built on spring framework and integrates the spring ecosystem.

Inegrates means spring boot makes different spring projects work together easy with little or no configurations.


GraalVM

GraalVM is a high performance Java Virtual Machine and development platform that can run Java and several other languages.

Its most popular feature is that it can compile java pplications into native executables (.exe/ Linux binary).


Problem with JVM

The JVM provides many features but it takes hundreds of milli seconds or even a few seconds for large appliations and memory usage is relatively high and a jdk or jre must be installed on the machine.

For long-running applications, JVM is best since startup time is not implicible.


GraalVM Native Image

Spring Boot applications can be converted into a Native Image.

native-image is a tool provided by Graal VM.

Converts jar to .exe.


Why GraalVM Native Image?

For serverless like aws lambda the application only starts when someone sends a request so graal vm natie image is highly recommended.

Suppose application takes 4 sec to start and the user waits for that 4 sec before the actual work even begins.

This is called cold start.

Memory also decrease for native image compared to spring boot application.

Microservices are best for GraalVM native image.


Build Native Image

Run:

mvn -Pnative native:compile
Enter fullscreen mode Exit fullscreen mode

Instead of producting .jar file it produces:

target/
└── application.exe
Enter fullscreen mode Exit fullscreen mode

Conclusion

Today I learned why Spring Boot was created, how it removes repetitive configurations, how stand-alone applications work, production-grade features, logging, connection pooling, JSON libraries, embedded servers, metrics, the Spring Platform, and how GraalVM Native Image helps reduce startup time and memory usage for serverless applications and microservices.

These are my Day 1 learning notes while going through the official Spring Boot documentation. In the upcoming days, I'll continue exploring more Spring Boot concepts in depth.

Top comments (0)