Before 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
PORTenvironment variable. Oracle Application Container Cloud uses this port to redirect requests made to your application. - The application must include a
manifest.jsonfile. 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 adeployment.jsonfile. - 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.jsonfile at the root.
What Do You Need?
- Access to an instance of Oracle Application Container Cloud Service
- A storage replication policy for your service instance (required for trial accounts)
- Maven 3.0+
- cURL 7.0+ with SSL support
- Book application service book-service.zip
- Git (Git CMD shell to execute cURL commands)
Create the Manifest.json File
- Extract the content of the
book-service.zipfile in your local system. - Create a
manifest.jsonfile at the same level than thepom.xmlfile and open it in a text editor. - 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" }
Prepare
the Application to Read the PORT Environment Variable
- In the
src/maindirectory, create theresourcesfolder. - In the
resourcesdirectory, create theapplication.propertiesfile. - Add the following content:
server.port=${PORT}
Compile
and Package Your Application
- Open a command-line window (or Terminal in Linux) and go to
the
book-servicedirectory. - Compile and package your application using the Maven
command:
mvn compile package
Deploy
Your Application to Oracle Application Container Cloud Service
- Open the Oracle Application Container Cloud Service console.
- In the Applications list view, click Create Application and then select Java SE.
- In the Application section, enter a name for your application and click Browse.
- In the File Upload window, select the
book-service-1.0-SNAPSHOT.zipfile located in thetargetdirectory, and click Open. - Keep the default values in the Instances and Memory fields and click Create.
- When the application is completely created copy the URL.
Test Your
Application
- Open a command-line window (or Terminal in Linux).
- Create a new book record using the following cURL command.
Replace the
app_endpointplaceholder 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 - Query all book entities.
curl app_endpoint/books - Update the
publishedproperty 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/1Note: The PUT method, update all the properties of the entity, if you don't specify one, the property is replaced with
null. - Delete the book.
curl -i -X DELETE app_endpoint/books/1
Want to Learn
More?
- Oracle Application Container Cloud Service in the Oracle Help Center
- Java SE 8: Creating a REST Service with Spring Data REST/JPA, and Tomcat for Oracle Application Container Cloud Service OBE
Deploy a Spring Application to Oracle Cloud