DEV Community

Cover image for Spring Boot: Everything you need to know, and what nobody told you. Part I
Weder Sousa
Weder Sousa

Posted on

Spring Boot: Everything you need to know, and what nobody told you. Part I

For all those who seek to solidify a career in application development using Java, they should also seek all knowledge in OOP (Object Oriented Programming), as I mentioned in my article 15 Tips to Become a Java Expert!, in the tip of learning a framework/lib, we must develop on other fronts that will support us in our career as a developer .

In the early days of application development using Java, it is known that the process of configuring development environments was a complex, boring and time-consuming moment.

But, over time, tools were created that had these functions configured and fell in love with developers, and the one that is most used in gigantic environments or even for small projects, this framework is called Spring Boot by Pivotal, it is It's possible to make our life a lot easier, a lot, lol.

Those of us who are part of a team of developers know that the time to finish our activities is short and of a lot of responsibility, and you can't waste time configuring a project instead of developing it, so in this article we'll go through the points you should know of this Framework, in addition to tips on best practices in its use.

Our mission here is to try to help you understand SpringBoot, to help you simplify the development of applications (Java), reducing the amount of configurations and optimizations, but remember not to reset the configurations, because they exist, but today we configure an application at a speed that 10 years ago was unthinkable.

In this article we will cover the following order to master the Spring Boot:

This article is divided into 4 parts:

Spring Boot: Everything you need to know, and what nobody told you. #Part02

Spring Boot: Everything you need to know, and what nobody told you. #Part03

Spring Boot: Everything you need to know, and what nobody told you.#Part04

Here we will start with Theory, on:

1. What is Spring
2. What is Spring Boot?
3. The Spring Components
4. Spring Boot Starter
5. Spring Boot AutoConfigurator
6. Spring Boot Actuator


1. What is Spring

Spring is a Java framework that was created with the aim of facilitating the development of applications, using the concepts of Inversion of Control and Dependency Injection. Inside it, there's Spring MVC and Core Technologies (it's the base of Spring, inside it's the dependency injection package).

2. What is Spring Boot?

Spring Boot is a framework that was born from Spring (MVC), a framework developed for the Java platform based on design patterns, IOC (inversion of control) and ID (dependency injection), both of which are standards for project that helps a lot to leave the code uncoupled.

Spring framework was created to simplify the configurations for web applications, however you still configured a lot of xml files, which did not manage to meet your objective, but which already helped you in great situations, in addition to the project, come out with your layers well defined.

Therefore, a new project was added to the framework to change this game and abstract all the complexity that a complete configuration can bring: O Spring Boot.

So Spring Boot 1.0 was released in April 2014. The Spring Framework 4.2.0, in this simpler and more direct development model, this framework was decisive for the use of the Spring ecosystem to become the darling of Programmers.

But what does it deliver that made it grow so much?

It provides most of the components needed in general applications in a pre-configured way, enabling an application running in production quickly, reducing the configuration and deployment effort, being already coupled to the tomcat Application server.

In short, Spring Boot is a pre-configured template for developing and running Spring-based applications.


3. The Spring Components

spring-boot, at the time of writing this article, is in version 3.0.1, and it is part of other spring. io with about 23 libs that help you build your applications:

  1. Spring Boot
  2. Spring Framework
  3. Spring Data
  4. Spring Cloud
  5. Spring Cloud Data Flow
  6. Spring Security
  7. Spring for GraphQL
  8. Spring Session
  9. Spring Integration
  10. Spring HATEOAS
  11. Spring REST Docs
  12. Spring Batch
  13. Spring AMQP
  14. Spring CredHub
  15. Spring Flo
  16. Spring for Apache Kafka
  17. Spring LDAP
  18. Spring Shell
  19. Spring Statemachine
  20. Spring Vault
  21. Spring Web Flow
  22. Spring Web Services

But with that many libs, how can I identify what I should understand first?*

Let's divide this first part into 3 fragments:

  • Spring Boot Starter
  • Spring Boot AutoConfigurator
  • Spring Boot Actuator

4. Spring Boot Starter

When we create an application we want to provide access to this application so we develop REST services; that we are currently using behind libs like Spring MVC, Tomcat and Jackson among many other dependencies for a single application.

So Spring Boot to help us decrease the number of manually added dependencies just by adding a dependency. Therefore, instead of manually specifying the dependencies, it is only necessary to add the following lib to our pom.xml:



<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-web</artifactId>
</dependency>



Enter fullscreen mode Exit fullscreen mode

When you run the maven command below:



mvn dependency:tree


Enter fullscreen mode Exit fullscreen mode

Result:

Image description

This command shows us all the dependencies of a lib:
in the case each level shows if it has other internal dependencies or not, in the first level we have:

org.springframework.boot:spring-boot-starter-json
org.springframework.boot:spring-boot-starter-tomcat
org.springframework:spring-web

As seen when running the command, Springboot's function is to combine the various dependencies arising from a Spring Boot project into a single dependency, eliminating the need to configure multiple dependencies in Maven or Gradle.

We noticed that if we had to add one by one this process would be very laborious. Therefore, Spring Boot uses starters in order to significantly decrease it.

Remember that this lib is the one that enables you to create controllers to use the annotations that we'll see later.


5. Spring Boot AutoConfigurator

Spring Boot autoconfiguration attempts to automatically configure your Spring application based on the jar dependencies you have added.

For example, if HSQLDB is in your classpath and you haven't manually configured any database connection beans, Spring Boot will automatically configure an in-memory database.

You need to opt-in to automatic configuration by adding @EnableAutoConfiguration or @SpringBootApplication annotations to one of your @Configuration classes.

Yes, but all the settings are in the official documentation, about this process.

It is responsible for managing the configuration process of a Spring Boot application, providing default settings and merging them with possible custom settings, you can create annotated classes that configure some function of your application.

In a Spring Boot application, the AutoConfigurator can be seen using the traditional @SpringBootApplication annotation, which is above the application's initialization method.

Internally, the aSpringBootApplication annotation is a combination of Spring's traditional @Configuration, @ComponentScan, and @EnableAutoConfiguration annotations.


6. Spring Boot Actuator

The Spring Boot Actuator, it provides us with endpoints that make it easier to obtain metrics from our application.

When configuring maven with the dependency below:



<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>


Enter fullscreen mode Exit fullscreen mode

Spring Boot AutoConfigurator defines that the web server should be exposed on localhost on port 8080, but you can redefine this port. But who makes the provision of this configuration on the web server is the Actuator.

In my github there is a project SpringBootActuatorPrometheus that teaches how to activate it and interconnect with Prometheus and Kibana, and visualize its graphs with micrometer metrics and spring boot Statistic.

This article is divided into 4 parts:

Spring Boot: Everything you need to know, and what nobody told you. #Part02

Spring Boot: Everything you need to know, and what nobody told you. #Part03

Spring Boot: Everything you need to know, and what nobody told you.#Part04

Top comments (1)

Collapse
 
drsimplegraffiti profile image
Abayomi Ogunnusi

Thanks for sharing