-
Notifications
You must be signed in to change notification settings - Fork 182
Spring hello sample application
This application is a simple Spring MVC application that displays the host and port name of the services which have been bound to the application.
This guide uses the command line interface (CLI) to deploy the "Spring Hello" sample application that is hosted in this github repository. The sample application contains a single Spring MVC controller and view that shows the IP and port number of the mysql, redis, and mongodb service bound to the application.
You can see it running on Cloud Foundry http://hello-spring-cli.cloudfoundry.com/
Refer to the Prerequisites for Sample Applications page for more information
Clone the git repository git@github.com:SpringSource/cloudfoundry-samples.git or via https using https://(user-name-here)@github.com/SpringSource/cloudfoundry-samples.git
>git clone git@github.com:SpringSource/cloudfoundry-samples.git
Cloning into cloudfoundry-samples...
remote: Counting objects: 3214, done.
remote: Compressing objects: 100% (2526/2526), done.
remote: Total 3214 (delta 662), reused 2419 (delta 408)
Receiving objects: 100% (3214/3214), 8.35 MiB | 1.41 MiB/s, done.
Resolving deltas: 100% (662/662), done.
>cd cloudfoundry-samples\hello-spring
>mvn package
[INFO] Building war: L:\projects\cloudfoundry-samples\hello-spring\target\hello-spring.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
The following is the transcript from running the 'push' command to deploy the application. You need to enter 'n' to deploy from a different directory.
Enter 'target' for the deployment path. For the application name we are going to use "hello-spring-cli" but you
should change it to something different.
Hit 'enter' to accept default up until you ar asked 'Would you like to bind any services to 'hello-spring-cli'. Then enter 'n'
>vmc push --no-start
Would you like to deploy from the current directory? [Yn]: n
Please enter in the deployment path: target
Application Name: hello-spring-cli
Application Deployed URL: 'hello-spring-cli.cloudfoundry.com'?
The system cannot find the path specified.
Detected a Java SpringSource Spring Application, is this correct? [Yn]: y
Memory Reservation [Default:512M] (64M, 128M, 256M, 512M, 1G or 2G)
Creating Application: OK
Would you like to bind any services to 'hello-spring-cli'? [yN]: n
Uploading Application:
The system cannot find the path specified.
Checking for available resources: OK
Processing resources: OK
Packing application: The system cannot find the path specified.
OK
Uploading (2K): OK
Push Status: OK
The --no-start option was used since we are going to create and bind three services to this application - mysql, mongodb, and redis.
Now if you list the applications you will see the newly created one
>vmc apps
+------------------+----+---------+-----------------------------------+----------+
| Application | # | Health | URLS | Services |
+------------------+----+---------+-----------------------------------+----------+
| hello-spring-cli | 1 | STOPPED | hello-spring-cli.cloudfoundry.com | |
+------------------+----+---------+-----------------------------------+----------+
At the start we have no provisioned services but can get a list of those available by executing the 'services' command
>vmc services
============== System Services ==============
+----------+---------+-------------------------------+
| Service | Version | Description |
+----------+---------+-------------------------------+
| mysql | 5.1 | MySQL database service |
| redis | 2.2 | Redis key-value store service |
| mongodb | 1.8 | MongoDB NoSQL store |
+----------+---------+-------------------------------+
=========== Provisioned Services ============
To create and bind a service to the hello-spring-cli application execute the command
create-service <service> <name> <app> Create a provisioned service and assign it <name>, and bind to <app>
For example
>vmc create-service mysql mysql-hello hello-spring-cli
Creating Service: OK
Binding Service: OK
>vmc create-service mongodb mongodb-hello hello-spring-cli
Creating Service: OK
Binding Service: OK
>vmc create-service redis redis-hello hello-spring-cli
Creating Service: OK
Binding Service: OK
Now if you list the services, you will see in addition to the System Services, you newly provisioned ones
>vmc services
=========== Provisioned Services ============
+---------------+---------+
| Name | Service |
+---------------+---------+
| mysql-hello | mysql |
| mongodb-hello | mongodb |
| redis-hello | redis |
+---------------+---------+
You can now start you app
>vmc start hello-spring-cli
Staging Application: OK
Starting Application: OK
and query for its status
>vmc apps
+------------------+----+---------+-----------------------------------+-----------------------------------------+
| Application | # | Health | URLS | Services |
+------------------+----+---------+-----------------------------------+-----------------------------------------+
| hello-spring-cli | 1 | RUNNING | hello-spring-cli.cloudfoundry.com | mysql-hello, mongodb-hello, redis-hello |
+------------------+----+---------+-----------------------------------+-----------------------------------------+
Now browse to the URL .cloudfoundry.com, in this case http://hello-spring-cli.cloudfoundry.com
You will see a web page that lists the IP address and port number of each service.
Refer to the Getting Started FAQ for more information