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.
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.
POM File
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.
spring.datasource.driver-class-name: oracle.jdbc.OracleDriver spring.datasource.url: “jdbc:oracle:thin:@//localhost:1531/MEM.PRFT.COM” spring.datasource.jdbcUrl: “jdbc:oracle:thin:@//localhost:1531/MEM.PRFT.COM” spring.datasource.username: “IIBAdmin” spring.datasource.password: “IIBAdmin” |
Additionally, add dialect information to application.yml file to indicate the variant of DB language.
spring.jpadatabase-platform: org.hibernate.dialect.Oracle10gDialect
Entity Class
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
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.
Service Class
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,
mvn package
java -jar target/MemberDetailService-1.0.0.jar
Very well explained…!