The “Pi” in the name of the Raspberry Pi refers to Python, but as a Java developer I love to know and experiment with the various Java frameworks I also use at work. Spring is the main one, and I wanted to develop a proof-of-concept application which provides REST API’s to store and retrieve sensor data with a database back-end on the Raspberry Pi.

This is an extract of an example application from my book “Getting Started with Java on Raspberry Pi” in which you can find a lot more info an examples about Java, Raspberry Pi, Pi4J …

Image for post

Image for post

Several examples from the book “Getting Started with Java on Raspberry Pi”

The code

The sources of this application are available in the GitHub JavaOnRaspberryPi repository which contains all the examples, links, schemes, etc. from my book.

The H2 database we will be using is a full-Java-solution which doesn’t need any additional installation but is fully part of the application itself.

There is a lot of “discussion” whether you should use H2 only for testing or can use it in production. In recent years it has evolved into a very stable database solution which in my opinion is a very good choice for embedded projects.

JPA is the persistence specification used to “communicate” with the database. It helps you to define which objects (entities) can be stored in a database in which structure (tables).

#spring-framework #raspberry-pi #java #programming #spring-boot

A Spring REST and H2 database application on the Raspberry Pi
3.45 GEEK