Friday, 23 September 2016

Using Oracle 12c with Pivotal Cloud Foundry Applications and Spring Boot

In this post I walk through what it would take to access Oracle 12c using a spring boot application deployed to Pivotal Cloud Foundry PCF all from my Macbook Pro. Of course this can be done outside of an isolated laptop like my Macbook Pro but handy while doing DEV/TEST and still being able to use Oracle 12c.


  • Oracle 12c instance
  • PCFDev 
  • Git Client

1. First you will need a 12c Database and the best way to do that is to use this Oracle VM image below. I use VirtualBox to start that up and it gives me a working 12c database out of the box.

Once imported into VirtualPort you will want to configure the Network to allow port forwarding on the database listener port of 1521 and perhaps SSH into port 22 if you need that. The 1521 Port Forward rule is vital to ensure your Macbook localhost can access the database VM using the listener port. It's setup as follows.

2. This isn't required but installing the Oracle 12c instant client will give you SQL*Plus and to me that's vital. You could use a GUI tool if that's what you like but for me SQL*Plus is more then good enough. Here is the link for Mac Os X install.

Verify Setup:

Note: I am using the IP address of my local Macbook pro. I could use "localhost" as I have setup a Port Forward rule to enable that BUT given I am using PCFDev it will need the IP address of my local Macbook pro to ensure it's talking to the right host to get to the Oracle 12c instance VM.

pasapicella@pas-macbook:~/pivotal/software/oracle$ sqlplus scott/tiger@

SQL*Plus: Release Production on Fri Sep 23 15:57:11 2016

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Last Successful login time: Fri Sep 23 2016 15:48:26 +10:00

Connected to:
Oracle Database 12c Enterprise Edition Release - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options


3. I use PCFDev and the reason is it's local to my MacBook Pro and I can get it to talk to the Oracle 12c instance easily. You can use any PCF as long as you have network access to your Oracle 12c instance.

Download from here :
Docs are here :

At this point your ready to go , so follow these steps to test your setup

4. Clone Spring Music as follows

$ git clone

5. Download the Oracle 12c JDBC driver from the location below and place it into "src/main/webapp/WEB-INF/lib" folder

6. Package as follows

$ ./gradlew assemble

7. Now lets create a CUPS service to enable our application to bind to Oracle 12c we do that as follows

Note: It's vital we use the IP address of your local Macbook Pro as PCFDev itself is a VM which referencing "localhost" will not find the Oracle Database instance

pasapicella@pas-macbook:~/apps/pcf-dev/demos/spring-music$ cf create-user-provided-service oracle-db -p '{"uri":"oracle://scott:tiger@"}'
Creating user provided service oracle-db in org pcfdev-org / space pcfdev-space as admin...

8. Now lets create a file called manifest-oracle.yml to use the CUPS service as shown below

- name: spring-music
  memory: 512M
  instances: 1
  random-route: true
  path: build/libs/spring-music.war
    - oracle-db

9. Push as follows

$ cf push -f manifest-oracle.yml


pasapicella@pas-macbook:~/apps/pcf-dev/demos/spring-music$ cf push -f manifest-oracle.yml
Using manifest file manifest-oracle.yml

Creating app spring-music in org pcfdev-org / space pcfdev-space as admin...

Creating route

Binding to spring-music...

Uploading spring-music...
Uploading app files from: /var/folders/c3/27vscm613fjb6g8f5jmc2x_w0000gp/T/unzipped-app274683538
Uploading 457K, 88 files
Done uploading
Binding service oracle-db to app spring-music in org pcfdev-org / space pcfdev-space as admin...

Starting app spring-music in org pcfdev-org / space pcfdev-space as admin...
Downloading binary_buildpack...
Downloading java_buildpack...
Downloading ruby_buildpack...
Downloading staticfile_buildpack...
Downloading nodejs_buildpack...
Downloading go_buildpack...
Downloading python_buildpack...
Downloading php_buildpack...
Downloaded java_buildpack
Downloaded binary_buildpack
Downloaded python_buildpack
Downloaded nodejs_buildpack
Downloaded ruby_buildpack
Downloaded go_buildpack
Downloaded staticfile_buildpack
Downloaded php_buildpack
Creating container
Successfully created container
Downloading app package...
Downloaded app package (27.5M)
-----> Java Buildpack Version: v3.6 (offline) |
-----> Downloading Open Jdk JRE 1.8.0_71 from (found in cache)
       Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.2s)
-----> Downloading Open JDK Like Memory Calculator 2.0.1_RELEASE from (found in cache)
       Memory Settings: -Xmx382293K -XX:MaxMetaspaceSize=64M -Xss995K -Xms382293K -XX:MetaspaceSize=64M
-----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from (found in cache)
-----> Downloading Tomcat Instance 8.0.30 from (found in cache)
       Expanding Tomcat Instance to .java-buildpack/tomcat (0.1s)
-----> Downloading Tomcat Lifecycle Support 2.5.0_RELEASE from (found in cache)
-----> Downloading Tomcat Logging Support 2.5.0_RELEASE from (found in cache)
-----> Downloading Tomcat Access Logging Support 2.5.0_RELEASE from (found in cache)
Exit status 0
Staging complete
Uploading droplet, build artifacts cache...
Uploading build artifacts cache...
Uploading droplet...
Uploaded build artifacts cache (108B)
Uploaded droplet (79.8M)
Uploading complete

0 of 1 instances running, 1 starting
1 of 1 instances running

App started


App spring-music was started using this command `CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.1_RELEASE -memorySizes=metaspace:64m.. -memoryWeights=heap:75,metaspace:10,native:10,stack:5 -memoryInitials=heap:100%,metaspace:100% -totMemory=$MEMORY_LIMIT) &&  JAVA_HOME=$PWD/.java-buildpack/open_jdk_jre JAVA_OPTS="$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/ $CALCULATED_MEMORY -Daccess.logging.enabled=false -Dhttp.port=$PORT" exec $PWD/.java-buildpack/tomcat/bin/ run`

Showing health and status for app spring-music in org pcfdev-org / space pcfdev-space as admin...

requested state: started
instances: 1/1
usage: 512M x 1 instances
last uploaded: Fri Sep 23 06:14:54 UTC 2016
stack: unknown
buildpack: java-buildpack=v3.6-offline- open-jdk-like-jre=1.8.0_71 open-jdk-like-memory-calculator=2.0.1_RELEASE spring-auto-reconfiguration=1.10.0_RELEASE tomcat-access-logging-support=2.5.0_RELEASE tomca...

     state     since                    cpu    memory         disk           details
#0   running   2016-09-23 04:15:22 PM   0.0%   844K of 512M   452K of 512M

10. Verify from SQL*Plus it has created the table ALBUM in the SCOTT schema as shown below
SCOTT@> describe album;
 Name           Null?    Type
 ----------------------------------------------------------------- -------- --------------------------------------------
 ID           NOT NULL VARCHAR2(40 CHAR)
 ALBUMID            VARCHAR2(255 CHAR)
 ARTIST             VARCHAR2(255 CHAR)
 GENRE             VARCHAR2(255 CHAR)
 TITLE             VARCHAR2(255 CHAR)


11. Test application in a browser

No comments: