Oracle by Example brandingDeploy a Spring Application to Oracle Cloud

part 0Before You Begin

This 15-minute tutorial shows you how to prepare a REST application built using Spring Data REST to be deployed to Oracle Application Container Cloud Service.

Background

Oracle Application Container Cloud Service includes Oracle Java SE Cloud Service, which lets you deploy Java applications to the Oracle Cloud.

For your application to run properly on Oracle Application Container Cloud Service, it must comply with the following requirements:

  • The application must be self-contained. The application must include everything it needs to run independently.
  • Your application must listen to requests on a port provided by the PORT environment variable. Oracle Application Container Cloud uses this port to redirect requests made to your application.
  • The application must include a manifest.json file. This file specifies information that Oracle Application Container Cloud Service requires to run your application properly. Optionally you can also specify additional information about instance scaling, environment variables, and service bindings in a deployment.json file.
  • The application must be bundled in a .zip, .tgz, or .tar.gz file. The application archive must include all the project dependencies and optionally the manifest.json file at the root.

What Do You Need?


part 1Create the Manifest.json File

  1. Extract the content of the book-service.zip file in your local system.
  2. Create a manifest.json file at the same level than the pom.xml file and open it in a text editor.
  3. Add the following content and save the file.
    {
        "runtime": {
            "majorVersion": "8"
        },
        "command": "java -jar book-service-1.0-SNAPSHOT.jar",
        "release": {
            "build": "150520.1154",
            "commit": "d8c2596364d9584050461",
            "version": "1.0"
        },
        "notes": "Book REST Application using Spring Data REST"
    } 

part 2Prepare the Application to Read the PORT Environment Variable

  1. In the src/main directory, create the resources folder.
  2. In the resources directory, create the application.properties file.
  3. Add the following content:
    server.port=${PORT}

part 3Compile and Package Your Application

  1. Open a command-line window (or Terminal in Linux) and go to the book-service directory.
  2. Compile and package your application using the Maven command:
    mvn compile package

part 4Deploy Your Application to Oracle Application Container Cloud Service

  1. Open the Oracle Application Container Cloud Service console.
  2. In the Applications list view, click Create Application and then select Java SE.
  3. In the Application section, enter a name for your application and click Browse.
  4. In the File Upload window, select the book-service-1.0-SNAPSHOT.zip file located in the target directory, and click Open.
  5. Keep the default values in the Instances and Memory fields and click Create.
  6. When the application is completely created copy the URL.

part 5Test Your Application

  1. Open a command-line window (or Terminal in Linux).
  2. Create a new book record using the following cURL command. Replace the app_endpoint placeholder with the URL of your application.
    curl -i -X POST -H "Content-Type:application/json" -d "{ \"title\" : \"Hamlet\",  \"author\" : \"William Shakespeare\",\"isbn\":\"978-0486272788\", \"published\":\"1937\",\"genre\":\"Novel\" }" app_endpoint/books  
  3. Query all book entities.
    curl app_endpoint/books 
  4. Update the published property of the book.
    curl -i -X PUT -H "Content-Type:application/json" -d "{ \"title\" : \"Hamlet\",  \"author\" : \"William Shakespeare\",\"isbn\":\"978-0486272788\", \"published\":\"1980\",\"genre\":\"Novel\"}" app_endpoint/books/1

    Note: The PUT method, update all the properties of the entity, if you don't specify one, the property is replaced with null.

  5. Delete the book.
    curl -i -X DELETE app_endpoint/books/1

Want to Learn More?