Let’s start creating a Spring Boot application..

  1. install STS ..download from here.. [Eclipse of your choice]
    https://spring.io/tools/sts
  2. Installing maven to run from command line
    https://codinko.wordpress.com/2015/12/02/maven-local-installation/3. Create a simple spring boot from maven archetype.mvn archetype:generate -DarchetypeGroupId=org.springframework.boot -DarchetypeArtifactId=spring-boot-sample-simple-archetype -DarchetypeVersion=1.0.2.RELEASE -DgroupId=com.codinko.code.cloud.springboot4 -DartifactId=cloud-springboot4 -Dversion=1.0.0-SNAPSHOTmvn-archetype-springboot.JPG

    // succesfully created..  Project created from Archetype in dir: D:\space.. BUILD SUCCESS

Import the project as maven project in your eclipse/STS workspace.

4. Create a Spring boot application in STS [Spring Tool Suite].

Reference: https://spring.io/blog/2015/03/18/spring-boot-support-in-spring-tool-suite-3-6-4

New -> Spring starter project -> packaging jar,type Maven, dependencies :web [support full stack web development including Tomcat and spring-webmvc]..

This is a web app. Let’s add a HelloController with a REST api that prints the name passed as parameter.
hello-controller.JPG
Right click on project and Run as Spring boot..

console1

http://localhost:8888/hello?name=codinko

In Application.properties, we have an entry :  server.port=8888

localhost8888-hello.JPG

Note: If you don’t have STS, the easy way is to use this online tool:    https://start.spring.io/

Notes:

Running a Boot App in STS
–  Spring boot apps created by the wizard come in two flavors ‘jar’ or ‘war’.
– The Starter wizard let’s you choose between them in its ‘packaging’ option.

A great feature of spring-boot is that you can easily create standalone ‘jar’ packaged projects that contain a fully functional embedded web server.

All you need to do to run your app, is run its Java Main type, just like you do any other plain Java application.

This is a huge advantage as you don’t have to mess around with setting up local or remote Tomcat servers, war-packaging and deploying.

If you really want to do things ‘the hard way’ you can still choose ‘war’ packaging.

However there’s really no need to do so because:

  • you can convert your ‘jar’ app to a ‘war’ app at any time
  • the Cloud Foundry platform directly supports deploying standalone Java apps.

 

Read more and Try this compulsory exercise mentioned here:
https://spring.io/blog/2015/03/18/spring-boot-support-in-spring-tool-suite-3-6-


Let’s push our project to github..

Go to github and create a repository.  let’s name it hello-boot.

The next page gives you these steps:
Open Git bash
cd existing_folder
git init
git remote add origin https://github.com/codinko/hello-boot.git
git commit -m “first commit”
git push -u origin master

When prompted, enter your credentials.
In Git repositories view, add existing local repo that you just created to view it from eclipse/ STS.

https://github.com/codinko/hello-boot


To understand a Spring Boot application that we just now created, its is mandatory to read this article. 

http://docs.spring.io/spring-boot/docs/current/reference/html/getting-started-first-application.html

Pending to read: http://projects.spring.io/spring-boot/

Cloud Foundry / PCF/ PWS

Cloud Foundry is an Open source PaaS, provides a fast and easy way to build, test, deploy and scale applications.
Pivotal Web Services, is an instance of PCF hosted by Pivotal.

  • Install Cloud Foundry Command Line Interface:
    https://docs.cloudfoundry.org/cf-cli/install-go-cli.html
    Test your installation by opening a terminal window and type cf. If your installation was successful, you can see the cf CLI help listing.
  • Register PWS [Pivotal Web Services] account.
    Pivotal provides free access for 1 year to Pivotal public cloud. Practice yourself!
    Create a Pivotal account – https://login.run.pivotal.io/login
  • Assuming you already have github account, and gitbash installed.

CLI Basics:
https://console.run.pivotal.io/tools

Login to the CLI
$ cf login -a api.run.pivotal.io
Get help in the CLI
$ cf help
Push an application
$ cf push your_app

Next Steps:
Install the CLI, Clone the app, Deploy the app to PWS thru CLI, view the logs:
Follow the below link to deploy a sample app [This one explains the project you can clone from github, how to push that app to PWS. Hence we are not repeating those steps here. Please read below one]

https://pivotal.io/platform/pcf-tutorials/getting-started-with-pivotal-cloud-foundry/introduction

cf auth email pwd  // this one worked from cygwin in windows

[The below one also works from windows terminal:
cf login -a https://api.run.pivotal.io –skip-ssl-validation -o yourorg -s yourspace ]

Then  cf push

$ cf push
FAILED
No org and space targeted, use ‘cf target -o ORG -s SPACE’ to target an org and space

– Go to your PWS account and find name of your ORG and SPACE

$ cf target -o my-org -s development

Now do $ cf push

 

cf-push-1.JPG

pws-org-space-screen1

Find logs:

cf logs cf-spring –recent


If you have a simple app created in STS, and you try to push the jar to PCF, it fails.
Because for deploying an app in PCF, the app needs to have  manifest.yml file.
When you do cf push, it is the manifest.yml that communicates to cf push, on how to deploy your application to PCF.

You can refer manifest.yml of the previous app, or refer the one below.
https://github.com/cloudfoundry-samples/hello-spring-cloud
https://github.com/cloudfoundry-samples/hello-spring-cloud/blob/master/manifest.yml

Lets create a sample app – https://github.com/codinko/hello-boot.git

Listing the HelloController.java, manifest.yml and application.properties for quick reference.

Let’s create the manifest.yml

Now do  cf login and cf push  application name

cf login -a https://api.run.pivotal.io –skip-ssl-validation -o codinko-org -s development

cd to project directory

cf push hello-boot

001-001.JPG

001-002

Let’s see the dashboard and our app from PCF

001-003

001-004

 

———————-

Connect to database:

https://pivotal.io/platform/pcf-tutorials/getting-started-with-pivotal-cloud-foundry/connect-a-database

How to connect this app to a mysql database/ add a mysql service – we’l cover soon..