myfirstprojectspring : first project created on Spring Boot to test and play with Spring Boot and API Rest
Class Book
Class Movie
MVC: @Controller, @RestController, and fake @Service
Web App: @Controller and ThyemLeaf engine Template: web.html
libraryRest : Project Spring Boot with only an HTTP connection to CRUD API Rest
@RestController and
fake @Service
All CRUD Operations upon ArrayList.
libraryRest2 : Project Spring Boot with only an API Rest and new features to complete the project
@RestController and
fake @Service
CommandLineRunner operating upon @Service
All CRUD Operations upon ArrayList on CommandLineRunner
ResponseEntity on @RestController response return
Security-starter on
POM dependency and
Application.properties user and password configuration
@Valid for validation Book Object
on createBook parameters and
and @NotBlank annotation
libraryWeb : Project Spring Boot with only a Web App
Template Engine: Thymeleaf, web.html:
Model/ModelAndView container-object on @Controller and
fake @Service
All CRUD Operations upon ArrayList
libraryH2Command : first project with only H2 DB JDBC Java Dependency and JPA DATA
Be CAREFUL : you must use version 1.4.99 H2 DB windows installer or platform-independent
@Entity Book
Interface CrudRepository <Book, String>
@id of @Entity Book is Title, as string
CommandLineRuner
we use CommandLineRunner to test H2 DATABASE CRUD
we use @Component
fake @Service
H2 DATABASE configuration datasource (url, username, password, driver)
spring.datasource.url=jdbc:h2:tcp://localhost/~/h2/library
spring.datasource.username=albert
spring.datasource.password=1234
spring.datasource.driver-class-name=org.h2.Driver
Choose dialect
H2Dialect or MySQL5Dialect
and Initialize a database using JPA DDL enum:
POM : dependencies
JPA DATA: spring-boot-starter-data-jpa and
H2 DATABASE: com.h2database
libraryH2Command2 : copy from the first project just to add an AUTO-GENERATED ID
with only H2 DB JDBC Java Dependency and JPA DATA
@Entity Book
Interface CrudRepository <Book, Integer>
@id of @Entity Book is Title, as Integer
customer : project with H2 DB JPA and all CRUD operations
with H2 DB JDBC Java Dependency and JPA DATA
@Entity Customer
Interface CrudRepository <Customer, String>
@id of @Entity Customer is id, as String
All CRUD Operations:
get : findAll
create : save
delete : findAndDeleteById
delete : deleteById
update : update
count : count
existsById : existsById
countByLastname : countByLastname (derived count query)
deleteByLastname : deleteByLastname (derived delete query)
libraryH2Command3 JPA @ManyToOne Unidirectional owning-side Many between @Entity User (reverse or not-owning side) and @Entity Book (owning side)
Core Concepts JPA and JPA mapping annotations
Be CAREFUL : compatibility matrix of versions JAVA, JPA and Hibernate ORM
H2 Java Database, SQL: Be CAREFUL : you must use version 1.4.99 H2 DB windows installer or platform-independent
Mapping entities JPA :
User <1:n> Book
@Entity Book and @BookService. User @Entity and @UserService (all CRUD operations)
Interface UserRepository <User, String> and @id of @Entity User is id, as string
Interface BookRepository <Book, String> and @id of @Entity Book is id, as string
CommandLineRuner : we use @Component
H2 DATABASE configuration datasource (url, username, password, driver)
Choose dialect: H2Dialect or MySQL5Dialect
and Initialize a database using JPA DDL enum : DDL enum cases
POM : dependencies
JPA DATA: spring-boot-starter-data-jpa and
H2 DATABASE: com.h2database
libraryH2Command4 JPA @ManyToOne and @OneToMany Bidirectional between @Entity User (not-owning side) and @Entity Book (owning side)
Core Concepts JPA and JPA mapping annotations with JPA H2 DB Applications.properties
Mapping entities JPA :
User <1:n> Book
Entities with all CRUD operations
@Entity Book , BookService @Service and BookRepository.
@Entity User , UserService @Service and UserRepostiory.
CommandLineRuner : we use @Component
Be CAREFUL : there is a tricky game here to make bidirectional solution useful in this particular case: user-book(physical one)
Be CAREFUL : don't print books from user.toString() by a default toString() cause you will create a recursive nightmare! Better to leave a simple toString() but if you are a brave programmer, try it!
libraryH2Command5 JPA @ManyToMany by @JoinTable between @Entity Author (owning side) and @Entity Book (inverse not-owning side)
Core Concepts JPA and JPA mapping annotations with JPA H2 DB Applications.properties
Mapping entities JPA :
User <1:n> Book <n:m> Author
Entities with all CRUD operations
@Entity Book , BookService @Service and BookRepository.
@Entity User , UserService @Service and UserRepostiory.
@Entity Author, AuthorService, @Service and AuthroRepostiory.
CommandLineRuner : we use @Component
libraryH2Command6 JPA @ManyToMany by @Entity Borrows between @Entity User (owning side) and @Entity Book (inverse not-owning side)
Core Concepts JPA and JPA mapping annotations with JPA H2 DB Applications.properties
UML example
Mapping entities JPA
User <1:n> Borrow <n:1> Book <n:m> Author
User <n:m> Book
Entities with all CRUD operations :
@Entity Book , BookService @Service and BookRepository.
@Entity User , UserService @Service and UserRepository.
@Entity Author, AuthorService, @Service and AuthorRepostiory.
@Entity Borrow, BorrowService, @Service and BorrowRepostitory.
CommandLineRuner : we use @Component
New package order : Project Folder Tree
employee MongoDB NoSQL and Spring Boot JSON and BSON data to Mongo Atlas Cloud.
Core Concepts and examples Spring Boot and MongoDB
Connection to DB Cloud
String Connection to DB: user, password, allowed IP
mongodb+srv://<username>:<password>@clustertest.0h8fd.mongodb.net/myFirstDatabase?retryWrites=true&w=majority
#Replace <password> with the password for the <username> user. Replace myFirstDatabase with the name of the database that connections will use by default. Ensure any option params are URL encoded.
spring.data.mongodb.uri=mongodb+srv://springbootviladoms:122344@clustertest.0h8fd.mongodb.net/employeeD
POM dependencies
Collection and document MongoDB:
@Document : employee
Repository : employeeRepository
(in this example there is NO service)
testing all CRUD operations with employeeRepository, this is a very bad practice because of :
DDD (Domain-driven Design)
testing response-time cloud-latency for all CRUD operations : output
employee2 MongoDB NoSQL and Spring Boot CRUD operations JSON and BSON data to Mongo Atlas Cloud.
Core Concepts and examples Spring Boot and MongoDB
Connection to DB Cloud:
spring.data.mongodb.uri=mongodb+srv://springbootviladoms:1234@clustertest.0h8fd.mongodb.net/employeeDB
POM dependencies
Collection and document MongoDB:
@Document : employee
Repository : employeeRepository
@Service : employeeService
employee3 MongoDB Image NoSQL and Spring Boot CRUD operations JSON and BSON data to Mongo Atlas Cloud.
Core Concepts and examples Spring Boot and MongoDB
Query methods
Mongo repositories
Connection to DB Cloud
POM dependencies
Collection and document MongoDB:
@Document : employee and employeeImages
Repository : employeeRepository and employeeImagesRepository
@Service : employeeService
employeeImagesController API Rest @RestController
employee4 MongoDB NoSQL and Spring Boot CRUD operations JSON and BSON data to Mongo Atlas Cloud with JAVA FAKER and @Query derivades
Core Concepts and examples Spring Boot and MongoDB
Connection to DB Cloud: Application.properties
spring.data.mongodb.uri=mongodb+srv://springbootviladoms:1234@clustertest.0h8fd.mongodb.net/employeeDB
JAVA Faker
POM dependencies
Java Faker Dependency
<dependency>
<groupId>com.github.javafaker</groupId> <artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
Collection and document MongoDB:
@Document : employee
Repository : employeeRepository
@Query("{age: {$gt : ?0}}")
List<Employee> findItemByAge(int age);
employeeDynamoDB AWS DynamoDB NoSQL and Spring Boot CRUD operations. Tests are done by Junit 5
Core Concepts and examples Spring Boot and DynamoDB
Dates are formatted as a long number, epoch format.
Connection to DB Cloud:
Configuration: DynamoDBConfiguration
Application.properties for local storage of pair-keys, Access keys (access key ID and secret access key) from AWS Amazon Security Credentials:
amazon.aws.accesskey=AKIA56F5DT6J4PVJNNUT
amazon.aws.secretkey=96TDFD4hqty7kuyQS33aCVDFKVTRy665FGffERATcp
(keys are FAKE)
POM dependencies
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-releasetrain</artifactId>
<version>Lovelace-SR16</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.11.64</version>
</dependency>
<dependency>
<groupId>com.github.derjust</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>5.1.0</version>
</dependency>
Objects DynamoDB:
Bean @DynamoDBTable(tableName = "Employee") : employee
@EnableScan Repository : employeeRepository
@Service : employeeService
demoLogin API WebSocket STOMP client Login and Spring Boot
Client Websocket (/resources/static):
POM dependencies
Model :
Controller: LoginController
Websocket configuration : WebsocketConfig
Project Folder Tree
securityDemo2 Security-starter, Spring Web/Thymeleaf (HTML/JS/CSS templates) and H2 in memory (data.SQL, BCryptPasswordEncoder())
Client Web (Thymeleaf injection web):
POM dependencies
password MUST be encrytped: https://bcrypt-generator.com/
Model :
Service : CustomerUserDetailService.java
Configuration:
WebSecurity : WebSecurityConfig
MvcConfig : MvcConfig.java
Project Folder Tree
customerThymeleaf Spring Web/Thymeleaf (HTML/JS/W3.css) and MongoDB with Employee document
Client Web (Thymeleaf injection web):
POM dependencies
Model :
Configuration QR:
Project Folder Tree
libraryRestH2Mongo MongoDB Image NoSQL and H2 SQL and Spring Boot CRUD operations JSON with API REST
Connection to H2 local
POM dependencies
Model : author, book, borrow and user
Controller: userRestController
Repository : author, book, borrow and user
Service : author, book, borrow and user
libraryRestH2Mongo2 MongoDB Image NoSQL and H2 SQL and Spring Boot CRUD operations JSON and BSON data to Mongo Atlas Cloud and H2 local storage with API REST
Core Concepts and examples Spring Boot and MongoDB
Connection to DB Cloud and H2 local
POM dependencies
Controller:
Repository : author, book, borrow, user and userImages
Service : author, book, borrow and user
libraryRestH2Mongo3 MongoDB Image NoSQL and H2 SQL and Spring Boot CRUD operations JSON and BSON data to Mongo Atlas Cloud and H2 local storage with API REST and WebSocket STOMP client.
Core Concepts and examples Spring Boot and MongoDB
Client Websocket (/resources/static):
Connection to DB Cloud and H2 local
Configuration WebSockekConfig class Stomp Websocket : enpoints and registry.
POM dependencies
WebJar Dependencies
Websocket dependencies
Model :
Controller:
Repository : author, book, borrow, user and userImages
Service : author, book, borrow and user