In this blog post, we will learn how to Migrate IIB REST application to Spring Boot.
The topics covered in this use case include:
- Create SpringBoot Project
- Creating Model class from Swagger
- Pom File
- Define Database Configuration
- Entity Class
- JPA Data Repository
- Rest Controller
- Service Class
- Build and Run the Project.
Application modernization is a growing area of focus for enterprises. If you’re considering this path to cloud adoption, this guide explores considerations for the best approach – cloud native or legacy migration – and more.
Create Spring Boot Project
Create a new maven project to implement a REST application to migrate your IIB REST application.
File → New → Maven project
Define ArtifcatID/Package as same as IIB REST application
Create Model Class from Swagger
Copy Swagger file from the IIB REST API and create a model class using the swagger and place it under com.perficient.restapi.model and com.perficient.restapi.handler package. I have used swagger editor to generate java classes from swagger.
Usually we will download and add external Jar files in shared Library for APIs in IIB. In spring boot project just need to add dependencies detail to the pom.xml. At the time of build/Maven updated all the dependency jars automatically downloaded to .m2 repository location.
Define Database Configuration
Back up your DB connection details from IIB REST API and place it under application.yml file as like below format to make a Data base connection.
Additionally, add dialect information to application.yml file to indicate the variant of DB language.
Get the select query from IIB code and create a bean class with the column names given in the query. Therefore all the column values automatically set to the bean class by the Spring frame work.
Annotate the bean class with @Entity and @Table
JPA Data Repository
This class is same as your invoking the select query in compute node. Create Interface called “MemDetailRepository” under com.perficient.restapi.dao package.
Below is the JPA native query to fetch the data from DB,
|@Query(“SELECT r FROM EntityBean r WHERE r.memberId = :memberId”)|
Table name in the select query should be same as your entity bean class name.
Rest controller class is equivalent to HTTPInput node in IIB. In Restcontroller class we need to define the URI, message format and the request method.
All the business logic’s should be implemented under the service class.
Build and Run the Project
No need to deploy the application to any specific server. SpringBoot is comes up with embedded Tomcat server for running the application.
Right Click you REST API and select Run As → Spring Boot App
Alternatively, you can run your application using below command,
java -jar target/MemberDetailService-1.0.0.jar