These instructions will walk you through deploying the Cloud Foundry Spring Music reference App using the Kf Cloud Service Broker for Google Cloud.
-
Building Java Apps from source: The Spring Music source will be built on the cluster, not locally.
-
Service broker integration: You will create a database using the Kf Cloud Service Broker and bind the Spring Music App to it.
-
Spring Cloud Connectors: Spring Cloud Connectors are used by the Spring Music App to detect things like bound CF services. They work seamlessly with Kf.
-
Configuring the Java version: You will specify the version of Java you want the buildpack to use.
Prerequisites
Install and configure Kf Cloud Service Broker .
Deploy Spring Music
Clone source
-
Clone the Spring Music repo .
git clone https://github.com/cloudfoundry-samples/spring-music.git spring-musiccd spring-music -
Edit
manifest.yml, and replacepath: build/libs/spring-music-1.0.jarwithstack: org.cloudfoundry.stacks.cflinuxfs3. This instructs Kf to build from source using cloud native buildpacks so you don't have to compile locally.--- applications: - name: spring-music memory: 1G random-route: true stack: org.cloudfoundry.stacks.cflinuxfs3 env: JBP_CONFIG_SPRING_AUTO_RECONFIGURATION: '{enabled: false}' # JBP_CONFIG_OPEN_JDK_JRE: '{ jre: { version: 11.+ } }'
Push Spring Music with no bindings
-
Create and target a Space.
kf create-space testkf target -s test -
Deploy Spring Music.
kf push spring-music -
Use the proxy feature to access the deployed App.
-
Start the proxy:
kf proxy spring-music -
Open
http://localhost:8080in your browser:

The deployed App includes a UI element showing which (if any) Spring profile is being used. No profile is being used here, indicating an in-memory database is in use.
-
Create and bind a database
-
Create a PostgresSQL database from the marketplace.
kf create-service csb-google-postgres small spring-music-postgres-db -c '{"region":" COMPUTE_REGION ","authorized_network":" VPC_NAME "}' -
Bind the Service with the App.
kf bind-service spring-music spring-music-postgres-db -
Restart the App to make the service binding available via the VCAP_SERVICES environment variable.
kf restart spring-music -
(Optional) View the binding details.
kf bindings -
Verify the App is using the new binding.
-
Start the proxy:
kf proxy spring-music -
Open
http://localhost:8080in your browser:
You now see the Postgres profile is being used, and we see the name of our Service we bound the App to.
-
Clean up
-
Unbind and delete the PostgreSQL service:
kf unbind-service spring-music spring-music-dbkf delete-service spring-music-db -
Delete the App:
kf delete spring-music

