You are on page 1of 22

Get Started with Spring Boot

From basic to advanced


Plan (séance 1)
1. Introduction
2. Architecture (Spring Boot Layers and workflow)
3. Tools and setup
4. Building First Application (build, setting up and adding depencies)
5. Managing SpringBoot application using Maven.
Introduction (FrontEnd VS BackEnd)
Introduction
Introduction
Introduction (WHAT IS SPRING BOOT?)
 Spring Boot is built on top of the Spring Framework.
 It's a more automated and simplified version of Spring.
 Spring Boot makes it easy to create an up and running application in a few
minutes,
 It is used to build stand-alone web spring applications
Introduction
 WHAT IS SPRING Data?
 Spring Data JDBC
 Spring Data JPA
Introduction (ORM)
Architecture
Let’s take a look at a high-level architecture diagram to see how the application behaves:
Architecture (Spring Layers)
 Spring Boot Architecture has four layers:

It consists of Views. i.e., contains all the This layer is the It is responsible for
the front-end part of the business logic. It equivalent of the performing the CRUD
application, consists of services Repository interface. operations.
is the equivalent of the classes. It is We write database This layer is simply the
Controller class. The responsible for queries inside this actual database that you
Controller class handles validation and interface. decide to use to build
all the incoming REST authorization. Is the only layer that your application
API requests (GET, communicates with the
POST, PUT, DELETE, Business layer and the
PATCH) from the Client. Database layer.
Architecture (SPRING BOOT WORKFLOW)
1.The Client makes an HTTP request.

2.The Controller class receives the HTTP


request.

3.The Controller understands what type of


request will process, and then it deals with
it.

4.If it is needed, it calls the service class.

5.The Service Class is going to handle the


business logic. It does this on the data
from the database.

6.If everything goes well, we return a JSP


page.
Angular + SpringBoot Architecture
Tools
Building First Application
 Allant sur le Site de Spring Boot / project / spring Initializr
 On crée un projet :
 Group: nom de domaine qui doit être unique
 Artifact : nom de livrable
 Name : prend automatiquement le même nom d’artifact
 Description : description de l’application
 Package : le nom de package
 -- depencies (add dependency: pour ajouter une dépendance)
 - spring boot dev tools (run automatique suite au changement)
 - lamboc : qui integre automatiquement les getters and setters)
 - spring data jdbc
Building First Application

  spring data jpa


  spring web : pour qu’on puisse utiliser l’architecture MVC
 spring security
 mySql driver

 Une fois on a choisie les deux dépendances (spring dev tools && spring web) pour
démarrer notre premier projet on fait download pour enregistrer le projet qui va être
importer par la suite par un IDE
Building First Application
1. Apres avoir installe jdk:
1. Cliquer sur bouton droit sur poste de travail / propriété /paramètre avancé de système/ variable
d’environement/ path (modifier) /ajouter le chemein de jdk (c:/program/java/jdk11,3) /selectionner et
ok
2. Allant sur sts window/ preference
3. Chercher « installed jre »
4. Vous trouvez par defaut
5. Cliquer et supprimer
6. Cliquer sur add
7. Standar vm
8. On chercher ou il existe notre JDK
9, (selection de dossier)
sélectionner la case à cocher
10, apply and close
Building First Application
 Cliquer de nouveau sur préférences:
 Chercher installed jre / execution envirment
 Choisir le version de jdk
Building First Application

 Créer un projet (file new spring starter project)


 Paramétrage et ajout des dependances
 Rq: target : contient le livrable de notre travail
 Rq: application.properties : fichier de configuration
 Une fois on a trouvé une erreure sur le fichier pom,xml
on ajoute au fichier pom,xml à
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>

</properties>
Et par la suite (bouton droit sur le projet/ maven /update project /selection de projet/ cocher la case « force
update ….»
Some settings Application.properties

server.port=8081
spring.datasource.url=jdbc:mysql://localhost:3306/dbgestionusers?
useUnicode=yes&useJDBCCompliantTimezoneShift=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
Example: Add user
Test controller

@RestController
public class TestController {
@RestController
//@RequestMapping(value = "/test", method = RequestMethod.GET)
public class UserController {
//@GetMapping("/{param}/{lastName}")
/*public String helloWorld(@PathVariable String param, @PathVariable
@Autowired
String lastName)
UserService userServ;
{
@PostMapping("/addUser")
return "Bonjour"+"---"+param+ "----"+lastName;
public User addUser(@RequestBody User u)
}*/
{
@GetMapping("/test")
return userServ.addUser(u);
public String helloWorld()
}
{
}
return "Bonjour !!! i'am here !!!";
}

User controller }
Example: Add user
Implement user service interface

@Service
public class UserService implements IUserService {
user service interface @Autowired
UserRepository userRep;
public interface IUserService {
@Override
public User addUser(User u) {
public User addUser (User u);
// TODO Auto-generated method stub
}
return userRep.save(u);
}
}

User Repository
public interface UserRepository extends CrudRepository<User, Long>
{ }
Diagramme de classe

You might also like