There's more...

Though Jakarta EE is perfect for microservices, other options use the same bases and may be a little lighter in some scenarios.

The clearer (and my favorite) way of doing it is by using Eclipse MicroProfile (http://microprofile.io/). It has defined the path and the standards for microservices in the Enterprise Java ecosystem.

As a standard, it has some implementations. Please refer to some of them here:

One last note about the code covered in this recipe— it would be nice in a real-world solution to use a Data Transfer Object (DTO) to separate the database representation from the service one.