Spring Java Controllers Generator

Generating a Java controllers Rest API

Overview

This generator enables the deployment of your OpenLegacy Hub project as a REST API service within a Java runtime environment. The output is a Spring Boot Java project, where only the service layer is generated as Java controllers. The contract of the OpenLegacy Hub project is exposed as a REST API using OpenAPI.

Once deployed and running, to apply changes from the Hub project—such as new methods, removed methods, or updates to input/output fields—you’ll need to regenerate the service, as the controllers are tied to specific methods. If the changes only affect internal logic, a simple restart of the service will be enough. If the project is using an OPZ provider, make sure to update the OPZ file before restarting the service.

📘

Supported Build tools

  • Gradle (default)
  • Maven

Generating from the CLI

  • First, generate a service using an OL Hub project and the Spring Java REST generator; see the ol generate command reference topic to learn more about service generation.
> ol generate --project "your_project_name" --generator spring-java-controllers
$ ol generate --project "your_project_name" --generator spring-java-rest --build-tool = gradle

The generated service folder is created. The folder is carrying the project name.


Build and Run a generated Project

# Building the API project 
gradle build
# Running the API as a Spring Boot project
gradle bootrun
# Building the API project into the .m2 and the target directory
mvn clean install -DskipTests
# Building the API project in the target directory
mvn clean package -DskipTests
# Running the API as a Spring Boot project
mvn clean spring-boot:run