Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Jacky_Liu
Product and Topic Expert
Product and Topic Expert
One of customers ask if  their existing  application deployed in tomcat server can be deployed into BTP runtimes . I think one option is BTP cloud foundry runtime. I checked the document , BTP cloud foundry has tomcat container. The tutorial Create a Java Application via Cloud Foundry Command Line Interface | Tutorials for SAP Developers give guidance about how. I tried it and if I follow the steps , I can succeed .

Then I think why not build docker image for the application run in Tomcat server and then deply the application into BTP Kyma runtime. I tried with springboot web application run with Tomcat server.

In this blog, I will share the steps :

Prerequisites:


1, Have installed Java JDK

2, Have installed Maven

3, Have installed docker

4, Have installed Intellij IDEA(Optional)

5, Kyma runtime has been activated in your BTP subaccount .

 

Step 1: Creat a SpringBoot application name tomaop


The following is the POM file .
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sap</groupId>
<artifactId>tomaop2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>tomaop2</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

The following is the controller class:
package com.sap.tomaop2.controller;
import com.sap.tomaop2.model.Employee;
import com.sap.tomaop2.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController

public class EmployeeController {

@Autowired
private EmployeeService employeeService;

@GetMapping(path = "/add/employee")
public Employee createEmployee(@RequestParam("empId") String empId,@RequestParam("firstName") String firstName,@RequestParam("secondName") String secondName){
return employeeService.createEmployee(empId,firstName,secondName);
}
@GetMapping(path = "/del/employee")
public String deleteEmployee(@RequestParam("empId") String empId){
employeeService.deleteEmployee(empId);
return "The employe " + empId +" has been deleted";
}

}

 

Run the application with the command: mvn  spring-boot:run



Test in browser:


 

Step 2: Buid docker file for the SpringBoot application


Add  google-jib plugin in pom file


Maintain docker account information in Intellij IDEA .


Run the following command to build the application:
mvn compile jib:buildTar


Check the generated tar file :


Load the tar file to Docker with following command:

docker load -i ./target/jib-image.tar


Check the image with the following command:

docker images | find "spring"


Push the image to docker hub with following command:


 

Step 3: Prepare Kyma deployment YAML file:


apiVersion: apps/v1
kind: Deployment
metadata:
name: tomaop
labels:
app: tomaop
spec:
selector:
matchLabels:
app: tomaop
strategy:
rollingUpdate:
maxUnavailable: 1
replicas: 1
template:
metadata:
labels:
app: tomaop
spec:
containers:
- image: registry.hub.docker.com/dockeraccount/springbootaop:latest
imagePullPolicy: Always
name: tomaop
ports:
- name: http
containerPort: 8080
env:
- name: DEBUG
value: "true"
- name: RENEWCERT_JOB_CRON
value: "00 00 */12 * * *"
resources:
requests:
memory: "512Mi"
cpu: "50m"
limits:
memory: "1000Mi"
cpu: "100m"
---
apiVersion: v1
kind: Service
metadata:
name: tomaop
labels:
app: tomaop
spec:
ports:
- name: http
port: 8080
selector:
app: tomaop

Step 4: Deploy the SpringBoot Application to BTP Kyma runtime:





Uload previous step YAML file


 



Step 5:Create API Rule for the service:







Step 6:Test with Chrome:



This is just a simple test, the actual situation is much more complecated with other stuffs like persistance , authorization ,etc .

 

The ends!

Thanks for your time!

Best regards!

Jacky Liu