To be clear. The content here is a content based on a free course. Noone can reproduce this material. If you wanna to know this material, my advice is to you access the free course. And if they end the course or start to ask money to study in the course? Well, this considerations are out of my control, but the DIO material is excelent and the course is amazing! If you acquire a DIO paln, you will have access to amazing courses.
Spring framework is an Java open source framework based on the concepts of inversion of control and dependency inversion.
Your structure is based on modules.
Overview of modules:
Java EE mainly in version preview of 5 was very verbose and burocratic and Spring Framework born as a more simple solution.
Overview:
Traditional way to work without IOC:
With IOC:
Overview:
More details:
- Singleton: the IOC container creates only one instance of the object;
- Prototype: it will be created a new object on each request to the container;
- HTTP - request: a bean will be created to each HTTP request;
- HTTP - session: a bean will be created to each user session;
- HTTP - global: application scope creates a bean to the context lifecycle of the application. In other words, while the application works, this bean will be avaliable.
Overview:
Overview:
Before Sprint Boot:
The role of Spring Boot is to aid in the configuration step. Dependency injection and inversion of control are concepts more related to Spring Framework, not to Spring Boot. The general idea is let you to put focus on the things related to the business.
Starters:
Starters are dependency descriptors. In the previous image, in the left part, please see the comments in green. To me (my comment and not a comment of the teacher, the left part of the image seemed a part of a pom.xml of Maven). In the right part is showed a more easy way to do the same thing using a starter. As you can see in the right part of the image, the Spring Boot is used in the right part of the image.
Benefits:
- Cohesion;
- Compatibles versions;
- Optimization of time;
- Simple configuration;
- Focus on business.
Some starters:
More starters:
Basic steps:
"initializr"is also known as Spring Initializr.
Site: https://start.spring.io/
We generated this starter there:
I had to generated a little different starter because some version change between my generation and the generation of the teacher while he was recording the class:
I versioned the generated starter with the name generated-initializer.zip in the root directory. I extracted this zip file with the name project-generated-with-initializer, also in the root directory.
To run this project, see the file and the run button that I pressed in VSCode in the next image:
We made a simple Calculadora class that we stored in the root directory of the package who has a simple "somar" method that add two integers. This is the wrong strategy to use this class, insatantiating manually the class. The class is not avaliable in the "Spring world" using dependency injection ans inversion of control. See:
Please see this video.
As I need to be more quick in my studies, I recorded this video trying to save some time.
Intruductory slide.
The teacher talked about application.properties when he talked about providing some values to the application.
He talked also that this is used when we will not have change in the values.
My video talking about this class: video.
In this class the teacher also talked about the use of application.properties, but through a ** bean** in this case. See my understainding of this class.
Some keywords:
Definition of JPA:
JPA - mapping:
I made a video about this class.
We will talk about interfaces and methods.
Here teacher used Spring Initializr to generate the project with the dependencies to use Spring Data JPA, see:
Pay attention that he both added the dependency of JPA as the dependency related to the RDBMS, in this case H2, but he could added the depenedency for MySQL or PostegreSQL if he wanted.
I recorded [this video](/home/andre/Área de Trabalho/spring-data-jpa.mp4) about this class.
Teacher configured some details of the connection with the PostgreSQL database in application.properties:
In the previous image you can see how JPA made the "magic" of updating the relational side with updating the Spring side.
The configurations that teacher get from the previous slide he pasted in application.properties:
Teacher also inserted the PostegreSQL dependency in pom.xml, but he can added this dependency when he generated the basic project in Initializr:
I made this video about this class.
Teacher teached us that Repository is similar to DAO (Data Access Object), see:
When we use the connection with a table in a "JPA world", we use AOP (aspect oriented programming, please see the result in Google, as example this link). We will use annotations. and when implement some interfaces we will can use some methods, like:
- save();
- findById();
- count();
- delete();
- and others.
Searching in the JPA world:
JPQL is the language used in the "JPA world".
An example of JPQL. As you can see in the previous image, the name findByEmailAddressAndLastname follows a standard. as you can see, you have "emailAddress" and "lastname" as the parameters of this function. The parts:
- find: the operation;
- By: indicates that the fields will be passed;
- EmailAddress: a field;
- And: connector;
- Lastname: another field.
Some JPA naming patterns:
Teacher also talked about query method x query override. In the first case, the defition of the way to opperate of the method is defined by its name, but in the second case we override the default functionality inseting a @query annotation and the query that we want. Please see the next image about finding user data based on its name using the SQL like operator:
You can see that in the query override, in the interface of the image we inserted what to do with the @Query annotation the @Param annotation of the param. JPA will map this value to the %:name in the query of the previous line.
I make this simple video about the class.
Slides of this class.
Github code related to this class.





























