Deploying a Spring Boot Microservice to Application Container — Oracle Cloud
By: Vinay Kumar
Tags: Microservices, Java, Oracle Cloud, Spring Boot, Cloud Computing

In the development of large systems, it is common to develop various components and libraries that implement various functions, ranging from the implementation of business requirements to technical tasks, such as an XML parser, for example. Microservices architecture allows to avoid monolith application for large system. It provides loose coupling between collaborating processes which runs independently in different environments with tight cohesion. So lets discuss it with an example.

For example imagine an online shop with separate microservices for user-accounts, product-catalog order-processing and shopping carts. So these components are inevitably important for such a large online shopping portal. For online shopping system we could use following architectures.

Shopping system with Microservices

In this architecture style the main application is divided in a set of sub applications called microservices. One large application is divided into multiple collaborating processes as shown below.

I will not talk in detail about microservices here. That is a separate topic to be discussed. I have created a web-app which uses Spring boot, Spring JPA, H2 in memory database and Thymeleaf template for building UI. Before going into implementation, please watch below video to see how end result will be displayed.

Why Spring Boot for Microservices Development

It comes with the ease of developing REST-service controllers, business services, and data repositories.

Setup new service by using Spring Boot

Expose resources via a RestController

Consume remote services using RestTemplate.

Oracle has built a platform to support micro-services development. Oracle Application container cloud is one of them. It is a run time container which can run application build in Java, Node.js, PHP, Python, and Ruby as of now. For more detailed information about Oracle ACCS, please read this article and another one. Oracle ACCS create run time docker container. Important point to take care of is host and port of your application. If working locally host is localhost and on 8080 port. In ACCS environment it will be definitely different. This can be managed via setting properties in main class of Spring boot as follow

Setting optional Configuration for ACC

Now look at implementation of SpringBoot application

Developer entity

In this application, I am integrating Spring Data JPA into our Spring Boot application. We will be extending CrudRepository which in turn extends the Repositoryinterface and hence there is no need of implementing our own methods.

CrudRepository

CrudRepository provides methods for the CRUD operations. This interface extends the Repository interface. When you define CrudRepository, you have to pass two parameters: type of the entity and type of the entity’s id field. This interface has the following methods:

S save(S entity)

T findOne(ID primaryKey)

Iterable findAll()

Long count()

void delete(T entity)

boolean exists(ID primaryKey)

Finally Spring Boot Controller class as

Spring Boot Controller.

Application project structure as below -

You can find the complete source code in my GitHub account. Now ,we will deploy the application to Oracle Application container cloud.

Deployment to Application Container Cloud

Navigate to Oracle Cloud dashboard. Click on Create instance.

2. On dashboard the user will see all oracle cloud services to which he has access. Click on Application container cloud.

3. Click on Create application on Application container cloud console.

4. Click on Java SE as application platform.

5. Upload archive zip file. Provide the application name, notification email, Java SE version, no of instance and memory information and click on create.

6. After a while the application is deployed and the user can view information about the deployed application.

Now Application is deployed successfully. Once deployed, you will also get mail notification as below.

If you hit browser with URL/developers , then application demo will work as shown in video.

That’s it . We deployed Spring Micro-services application successfully. If you come across any issues or want to check log then navigate to Administration section on left side and click on logs tab. Logs are stored via Oracle Storage cloud service.

If you want to connect application with database on cloud then on deployment section, you can connect with Oracle Database cloud service or MySql cloud service via Service binding section. You can also set environment variable at run time in deployment section.

That’s all for now. Happy learning on Oracle Cloud.