SAP Cloud Platform supports running J2EE applications. But most develops are not building Java Web Application from EJB/Servlet any more. They rather use framework to build up their app. Spring Framework from Pivotal is a popular one which you can build rapidly with just a few lines of codes and it is open source.
Getting a Spring Boot app running on SAP Cloud Platform is not so strait-forward as the platform already provides Tomcat container and some other stuffs which interfere with Spring Boot libraries so you need to work a bit more to get them running properly on the platform.
The introduction of SCP on Cloud Foundry makes also it easier to run. So in this guide, I will show you how to build a Hello World Spring Boot app on Cloud Foundry platform then will show what you need to do more to get it run on SAP-own Neo environment.
Create a Hello World Application
Create a new Maven project.
Populate the pom.xml file with the following:
Create a package and create your application class:
Create a (REST)controller class and define your endpoint:
Build and test running your application and you should see a hello message at http://localhost:8080/
Build and Deploy on SCP Cloud Foundry
To deploy Spring Boot App on Cloud foundry environment, you need to exclude
spring-boot-starter-tomcat from the JAR file by include the following in the pom.xml
<scope>provided</scope> means this library is already provided on the platform so no need to include it in the JAR.
Rebuild your project and upload deploy JAR file on SCP CF.
Note: If you don’t want to input application properties every time, you can create manifest.yml and select Use Manifest when deploying. See a sample of manifest file from here.
Wait until the application is started and turned green.
Click the URL to access your application.
Deploy using Command Line Interface (CLI)
Deploying JAR file via the web interface most of the time fails with unknown error. There’s no log file telling you the root cause either.
So let’s use CF CLI to push codes to Clous Foundty and let it build and deploy for us.
Before we use the command, make sure to create manifest.yml first.
Log in to Cloud Foundry environment.
$ cf api https://api.cf.eu10.hana.ondemand.com
Setting api endpoint to https://api.cf.eu10.hana.ondemand.com...
OKapi endpoint: https://api.cf.eu10.hana.ondemand.com
api version: 2.94.0
Not logged in. Use 'cf login' to log in.
$ cf login
API endpoint: https://api.cf.eu10.hana.ondemand.comEmail> firstname.lastname@example.orgPassword>
OKTargeted org Xxxxxxxxxxxtrial_trialTargeted space devAPI endpoint: https://api.cf.eu10.hana.ondemand.com (API version: 2.94.0)
After log in, then you can use command
cf push. Then you should see something like this:
Showing health and status for app app12345 in org Xxxxxxxxxxxtrial_trial / space dev as email@example.com...
OKrequested state: started
usage: 512M x 1 instances
last uploaded: Sun Oct 1 04:24:50 UTC 2017
buildpack: client-certificate-mapper=1.3.0_RELEASE container-security-provider=1.10.0_RELEASE java-buildpack=v3.19-https://github.com/cloudfoundry/java-buildpack.git#727297d java-main open-jdk-like-jre=1.8.0_144 open-jdk-like-memory-calculator=2.0.2_RELEASE open-...state since cpu memory disk details
#0 running 2017-10-01 11:26:01 AM 49.5% 282.1M of 512M 142M of 512M
This means your application is deployed and started.
Refer this page for instructions to install CF CLI.
Installing the cf CLI | Cloud Foundry Docs
Customizing the Cloud Foundry Deployment Manifest for AWS
Build and Deploy on Neo Environment
Include one more provided dependency in pom.xml:
Make the build to WAR by also adding this tag. Neo does not support JAR!
Make sure your application is extending SpringBootServletInitializer and override method configure. This will tells the platform which endpoint to bind and expose. Otherwise, you cannot access your application and always get 404 Not Found.
Build your application and deploy WAR file to SCP Neo.
Start your application and click URL to access your application.
Note: If you want to access your application at root URI then change finalName to
ROOT in pom.xml (Any better way?!?)
Apart from web cockpit, you can deploy your application from Eclipse IDE or Console Client. For more information, check out this documentation:
My source codes are available at GitHub:
spring-boot-helloscp - Hello World Spring Boot App for SAP Cloud Platform (CF/Neo)
Make JAR, not WAR.