Skip to main content
This post was originally published on the Platform.sh blog and reflects information from the time of publication.
Divide and conquer—the most critical Roman strategy—works efficiently in several areas. The context to take any giant issue and break it down into small pieces to make the job easier to understand, making it scalable and agile, and allowing more people to work on it to deliver faster. The microservice was born from this principle. The microservices architecture is a variant of the service-oriented architecture style that structures an application as a collection of loosely coupled services. In a microservices architecture, services are fine-grained, and protocols are lightweight. In Java, there are several frameworks (including Spring Boot, which we explored in a previous post). Today, let’s walk through the Java/JakartaEE side and talk about the Eclipse MicroProfile. The goal of the Eclipse MicroProfile initiative: to optimize Enterprise Java for the microservices architecture. It’s based on a subset of JakartaEE APIs, so we can build MicroProfile applications the same way we build JakartaEE ones. MicroProfiles define standard APIs for building microservices and deliver portable applications across multiple MicroProfile runtimes.

Show me the code

Ok, let’s start talking code. Not to digress (you’ll see my rationale in the next paragraph!), but in August, I’ll be starting a fantastic trip around Latin America to talk about Java, cloud computing, NoSQL, and I’ll be joining the Oracle Groundbreakers Tour LATAM 2019: To celebrate, let’s create a microservice with an Eclipse MicroProfile that manages countries for the Latin America trip. The first step in the Maven project is to set up the libraries needed for the project.
There’s no specification that covers the storage technology on the Eclipse MicroProfile, but once the MicroProfile has synergy with Jakarta EE, it will use a Java Persistence API (JPA). JPA entity classes are user-defined classes whose instances can be stored in an annotation-driven database. There are annotations such as @Entity, @Table, @Id, and @Column that make the object-to-database transition smoother than doing it manually, helping to speed development.
After defining the model, let’s enable the JPA and CDI technologies. In the root of the code, we’ll create two files in the folder src/main/resources/META-INF

Bean.xml. The bean.xml file will enable the CDI (Contexts and Dependency Injection), which is a standard dependency injection framework on Jakarta EE. It enables us to manage the lifecycle of stateful components via domain-specific lifecycle contexts and inject components (services) into client objects in a type-safe way.

Persistence.xml. The persistence.xml is the central piece of configuration. That makes it one of the most important files of your persistence layer. It defines the JPA provider, the driver, user, password, and so on. For this sample code, we’ll use PostgreSQL, but don’t worry about the blank configuration; it will be defined in real time using Platform Config Reader.

Our next step is to combine the JPA and CDI. In brief, this combination will make the EntityManagerFactory eligible through all applications using the Inject annotation.
The CDI has impressive features, including the scope. Therefore, we can define an EntityManager to be used in the whole application, and when the application shuts down, it will close the containers one by one.
The Country entity class and the database integration are now ready. The next step: the service layer with the CountryService class, which is the layer that integrates the database with the business. The CountryService class will do the essential CRUD operations on PostgreSQL to handle the transaction we need for the transactional annotation. It’s easy!
The last piece of Java code is the rest integration, where we’re going to use a JAX-RS that belongs to both Eclipse MicroProfile and Jakarta EE. On JAX-RS, all HTTP methods and paths are annotation-driven, using intuitive annotations such as @GET, @PUT, or @DELETE. We can now do the integration in a more relaxed way, saying “juguetón!” (“playful” in Spanish).
The last class enables the JAX-RS and defines the root URL for the services.

Platform.sh structure

The Java application is now ready to go! The next step is to set up the Platform.sh files required to manage and deploy the application. In our first Java post, we took a deep dive into these three files:
  • One Router (.platform/routes.yaml). Platform.sh allows you to define the routes.
  • Zero or more service containers (.platform/services.yaml). Platform.sh allows you to completely define and configure the topology and services you want to use on your project.
  • One or more application containers (.platform.app.yaml). You control your application and the way it will be built and deployed on Platform.sh via a single configuration file.
The file that will change in this post is the service file, so you can define a database, search engine, cache, and so on. In this project, we’ll set up PostgreSQL instead of MySQL.
We’ll keep the route file the same as in the first post, but we’ll change the platform.app.yaml to run thorntail uberjar.
The application is now ready, so it’s time to move it to the cloud with Platform.sh using the following sets:
  • Create a free trial account.
  • Sign up with a new username and password, or login using a current GitHub, Bitbucket, or Google account. If you use a third-party login, you’ll be able to set a password for your Platform.sh account later.
  • Select the region of the world where you want your site to live.
  • Select the blank template.
After this wizard, Platform.sh will provision the whole infrastructure to you, as well as provide a Git remote repository. Before access, remember to set the SSH keys. The Platform.sh Git-driven infrastructure will automatically manage everything your application needs to push it to the master remote repository. You only need to write your code—including a few YAML files that specify your desired infrastructure—and then commit it to Git and push.
The code pushed will create the Java application, a PostgreSQL instance, and, when it’s done, will return an IP address to the service. Let’s test the application. To test a REST application, any HTTP client is suitable.
And just like that, we’ve created our first Eclipse MicroProfile application at Platform.sh! But is there any way to make this process easier?

New Eclipse MicroProfile templates have arrived

We’re proud to announce that four new Java templates have arrived, and these new templates are all Eclipse MicroProfile providers: Thorntail Thorntail offers an innovative approach to packaging and running Java EE applications by packaging them with just enough of the server runtime to “java -jar” your application. It’s MicroProfile compatible, too. And it’s all much, much cooler than that. https://thorntail.io/ Payara Micro Payara Micro is the open-source, lightweight, middleware platform of choice for containerized Java EE (Jakarta EE) microservices deployments. Less than 70MB in size, Payara Micro requires no installation or configuration. And there’s no need for code rewrites, so you can build and deploy a fully working app within minutes. https://www.payara.fish/software/payara-server/payara-micro/ kumuluz Develop microservices with Java EE/Jakarta EE technologies and extend them with Node.js, Go and other languages. Migrate existing Java EE applications to microservices and cloud-native architecture. https://ee.kumuluz.com/ Apache TomEE Apache TomEE is the Eclipse MicroProfile flavor that uses several Apache Project flavors, including Apache Tomcat and Apache OpenWebBeans. In this post, we took a dive into the fantastic world of Eclipse MicroProfiles. We defined the concept of microservices and how to integrate them with JPA. There are many more combinations coming to our Java stack to make Java developers’ lives easier using the latest generation of PaaS. If you’re in any of the cities I’ll be visiting in my upcoming tour, please feel free to contact me on Twitter; it’ll be amazing to get together and talk about Java while drinking something tropical from coconuts. Hasta la vista!!!
Last modified on April 27, 2026