Creating a Simple SpringBoot App and Deploy it on Top of Openshift in Less than Two Minutes

Today im trying to demonstrate how easy and fast to deploy a Spring Boot application on ton of Openshift Platform. But before we go too far, let us familiarize ourself with Openshift. Openshift is a Red Hat product which is a leading hybrid cloud, enterprise Kubernetes application platform. It lets you easily and quickly build, develop, and deploy in nearly any infrastructure, public or private. Whether it’s on-premise, in a public cloud, or hosted.

For this scenario, im trying to deploy a hello world apps which are build using Spring Boot. It only consist of 2 java class, and a configuration file (maven). Below is my main java class.

package com.edw.test.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

And below is the java class im using for controller,

package com.edw.test.demo;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
public class IndexController {
    @GetMapping("/")
    public HashMap get() {
        return new HashMap(){{
            put("Message", "Hello World");
        }};
    }
}

And my pom.xml file,

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.edw.test</groupId>
    <artifactId>demo</artifactId>
    <version>1.0.1</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

After everything runs well on your local, lets put those code online by using Github. Once published to Github, remember to copy your github’s project url. We shall need it later.

First thing to do after creating your code is creating your free Openshift account, you can login to it with your RedHat Developer account. Next is opening your Openshift web console, and click “create project” button and insert its name,

Click on project and choose “Browse Catalog”,

And chose RedHat Open JDK 8, and create application

And below is perhaps the most important feature, that is inserting your github url on Openshift. So that it can take your code and build it accordingly. And dont forget to checklist “Create Route”.

Once application is successfully created, it will shows logs as shown below and also it will show list of pods and its status,

Next is checking where is our route,

Clicking on it will show to the index page of our SpringBoot app,

Have fun using Openshift (^)

Google+

No Comments

Leave a Comment

Please be polite. We appreciate that.
Your email address will not be published and required fields are marked


:-[ (B) (^) (P) (@) (O) (D) :-S ;-( (C) (&) :-$ (E) (~) (K) (I) (L) (8) :-O (T) (G) (F) :-( (H) :-) (*) :-D (N) (Y) :-P (U) (W) ;-)