A very basic example on how to build a RESTful web service with Spring Boot 2.
On startup, Spring will set up an in-memory HSQL database. The database schema will be generated by Hibernate, matching
the given JPA entities in the backend.domain package. When the Spring application context has been initialized, the
database will be filled with some randomized dummy entries; see the SampleData component for details.
- JDK 8 or higher is required
- Maven 3 or higher is required
To launch the server, build the project with Maven and simply start the jar file:
mvn clean package && java -jar target/backend.jar
The application shows examples for the following use cases:
- configuring a Spring application via annotations and application.properties file
- serviing static web content with the Spring Boot app (see the
static/folder) - creating an in-memory database
- connecting to a database from a Spring application
- dependency injection with Spring
- specification of JPA entities
- using Spring data repositories inside a Spring application
- using Spring data repositories as RESTful webservices
- using Spring Projections as a lightweight alternative to database views
- using Spring MVC REST controllers which offer more flexibility for when defining a web service API
- during database schema generation, the HSQL database might throw an error; the schema generation should succeed nonetheless and the application should still be usable with all sample data