Objects are stored in an H2 database, accessed by JPA, and then wrapped in a web layer by Spring MVC so that they can be served on the web.
- Spring Boot
- Spring Data
- Spring MVC
- Spring HATEOAS
- H2 database
- Java Persistence API
- Docker
- Maven
Hal is a hypermedia format used to represent resources and to connect them in a usable way by (1) embedding related resources and (2) listing related links to other resources. Each HAL representation includes a map containing a list of links to navigate from the resource and an optional map of embedded resources to find the entire resource via its self link.
First rule of REST is to never talk about...is to never delete a column, even if it means repeating information
- Method References
- Streams
- HATEOAS
- Spring HATEOAS
- String Request and Response Body
- REST and HAL
- REST and HAL 2
- Spring Data JPA
- Spring Boot Maven
- Official Apache Maven documentation
- Spring Boot Maven Plugin Reference Guide
- Create an OCI image
- Spring Web
- Spring Data JPA
Classes are package-private by default. To define the JPA entity, an empty protected constructor that wont be used is written to follow the bean structure and a public constructor is the one used to create instances of the model to be stored in the database. The unique id for each object is annotated with @Id so that JPA recognizes it to be such and @GeneratedValue tells JPA to generate the value instead of doing so manually. Other properties of the object are left unannotated and assumed to be mapped to columns of the same name. JPA requires a repository to work. The apex interface, Crudrepository, provides CRUD functions that operate on the database, PagingAndSortingRepository extends CrudRepository and provides methods to do pagination and sorting records, and JpaRepository extends PagingAndSortingRepository to provide JPA-related methods (i.e. flushing the persistence context and deleting records in a batch) (Ken Chan 2012). Usually in Java applications, an interface containing abstract methods needs an implementation, but Spring Data JPA does this automatically when the application is run.
Basically, a Spring Boot application uses Hibernate to map application-domain-model-objects to the relational-database. Usually, a Java programmer would use the Java Persistence API (JPA) to interact with the object relational mapper which involves declaring Entity's and relationships between Entity's, using an EntityManager to perform database interactions and defining a repository interface. By adding Spring Data JPA, the repository interface is generated automatically and EntityManager operations are abstracted into a black box, saving the programmer from writing more-or-less boilerplate database interaction code and XML configurations.
The @SpringBootApplication annotation adds the @Configuration, @EnableAutoConfiguration and @ComponentScan annotations. The SpringApplication.run() method launches the application