Skip to content

Latest commit

 

History

History

spring-boot-datastore

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Holon platform examples: JAX-RS and PropertyBox using Spring Boot and a Datastore

This is one of the Holon Platform example projects.

This example shows how to setup RESTful server and client applications using the Holon platform JAX-RS module Spring Boot support, with both sides PropertyBox data container support using JSON as data exchange format, leveraging on the Holon platform JSON module Jackson JAX-RS support, and a JDBC Datastore as data store.

This is the Datastore version of the JAX-RS and PropertyBox using Spring Boot example.

Topics

This example addresses the following topics:

  • Setup a JAX-RS server RESTful API with PropertyBox JSON support using Spring Boot.
  • Use the @PropertySetRef annotation to handle PropertyBox type requests
  • Setup a JAX-RS client with PropertyBox JSON support.
  • Obtain and use RestClient to invoke API operations involving PropertyBox object types and handle errors.
  • Use a JDBC Datastore for data persistence.

Example structure

This JAX-RS server implements a simple RESTful API to provide the Product data model entity management, backed by a H2 database table named products, using a JDBC Datastore for data management.

The schema.sql file creates the products table in the test H2 schema at application startup.

The server API uses the PropertyBox class as data container and JSON as data exchange format, leveraging on the Holon platform JSON module Jackson JAX-RS support.

The ProductEndpoint class represents the API endpoint and provides operations to get a product, get all products and create/update/delete a product. It is declared as a singleton Spring bean through the @Component annotation and it is auto-configured as JAX-RS resource by the Holon platform auto configuration facilities.

The ProductStore Spring bean uses the JDBC Datastore to access and manage the products data using the products database table. The JDBC Datastore is automatically configured and bound to the DataSource declared in the application.yml properties file by the Holon platform DataStore auto configuration classes, imported as dependency using the Holon JDBC Datastore with HikariCP starter declared in the project's pom file:

<dependency>
	<groupId>com.holon-platform.jdbc</groupId>
	<artifactId>holon-starter-jdbc-datastore-hikaricp</artifactId>
</dependency>

The Client unit test class performs a set of API operations using a default RestClient instance obtained through the static forTarget() method, which creates a default RestClient implementation relying on the available RestClientFactorys (in this example, a standard platform JAX-RS Client based implementation will be created) and setting a default base target URI.

The Client test class output will be:

Created URI: http://localhost:{port}/api/products/1
Created id: 1
Updated description: Updated
Created URI: http://localhost:{port}/api/products/2
Products: 1 - Updated; 2 - Product 2
Deleted product with id: 1
Deleted product with id: 2
Products count: 0

Spring boot starters

The Holon platform provides a set of Spring Boot starters to quickly setup a JAX-RS server with different server runtimes and JSON providers.

In this example, the starter dependency declared in the project pom uses Jersey as JAX-RS server implementation, Tomcat as embedded servlet container and Jackson as JSON provider:

<dependency>
	<groupId>com.holon-platform.jaxrs</groupId>
	<artifactId>holon-starter-jersey</artifactId>
</dependency>

You can simply replace this dependency with another one among the available the Holon Platform JAX-RS starters to use a different JAX-RS implementation / embedded servlet container / JSON provider combination, for example to use Undertow as servlet container and/or Gson as JSON provider or Resteasy as JAX-RS implementation:

Starter Artifact id Description
holon-starter-jersey Spring Boot JAX-RS server starter using Jersey, Tomcat and Jackson as JSON provider
holon-starter-jersey-gson Spring Boot JAX-RS server starter using Jersey, Tomcat and Gson as JSON provider
holon-starter-jersey-undertow Spring Boot JAX-RS server starter using Jersey, Undertow and Jackson as JSON provider
holon-starter-jersey-undertow-gson Spring Boot JAX-RS server starter using Jersey, Undertow and Gson as JSON provider
holon-starter-jersey-client Spring Boot JAX-RS client starter using Jersey and Jackson as JSON provider
holon-starter-jersey-client-gson Spring Boot JAX-RS client starter using Jersey and Gson as JSON provider
holon-starter-resteasy Spring Boot JAX-RS server starter using Resteasy, Tomcat and Jackson as JSON provider
holon-starter-resteasy-gson Spring Boot JAX-RS server starter using Resteasy, Tomcat and Gson as JSON provider
holon-starter-resteasy-undertow Spring Boot JAX-RS server starter using Resteasy, Undertow and Jackson as JSON provider
holon-starter-resteasy-undertow-gson Spring Boot JAX-RS server starter using Resteasy, Undertow and Gson as JSON provider

For the client side:

Starter Artifact id Description
holon-starter-resteasy-client Spring Boot JAX-RS client starter using Resteasy and Jackson as JSON provider
holon-starter-resteasy-client-gson Spring Boot JAX-RS client starter using Resteasy and Gson as JSON provider

Documentation

The complete Holon Platform reference guide is available here.

For the specific documentation about the modules and the components used in this example see:

System requirements

The Holon Platform is built using Java 8, so you need a JRE/JDK version 8 or above to build and run this example projects.

License

All the Holon Platform modules and examples are Open Source software released under the Apache 2.0 license.

Holon Platform Examples

See Holon Platform Examples for the examples directory.