Skip to content

datianshi/cf-services101

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cf-services101

Cloudfoundry convieniently manages service dependencies for the apps. This repo takes the example of injecting a datasource to explain different ways wiring services in the cloudfoundry.

Running the app in local


mvn clean package && java -jar target/demo-0.0.1-SNAPSHOT.jar

The app will run locally with H2 in memory database configured as H2DataSourceConfig

http://localhost:8080/test would show some dummy string in database

Running the app in cloudfoundry

There are four ways of injecting dependencies, in this example:

  • EnvironmentDataConfig: Using environment variables with spring profile, parse-env
  • ParseServiceDataConfig: Bind with cloudfoundry broked service and parse the VCAP_SERVICES env variables with spring profile, parse-vcap
  • ParseUserDefinedDataConfig: Bind with cloudfoundry user defined service and parse the VCAP_SERVICES env variables with spring profile, user-defined
  • SpringCloudDataConfig: Bind with cloudfoundry services with spring cloud framework. spring profile, spring-cloud

How to deploy these examples using this application

Deploy the in-memory database dependency to the app

  • The manifest file is using spring profile: "default"
cf push

Bind the service to the application

  • Create a service with pivotal cf mysql services broker
cf create-service p-mysql plan test
  • Bind the service to the demo app
cf bind-service demo test

Create tables and schemas to the database

  • Find the database credentials for the demo app
cf files demo logs/env.log

The database information will be found in the VCAP_SERVICES env variables and user should connect to the database with any mysql client and run the test.sql to create data

Deploy the app with different profiles

By changing the manifest.yml SPRING_PROFILES_ACTIVE value, user is able to test and understand different strategies of the service dependencies.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages