<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ângelo Galvão</title>
    <description>The latest articles on DEV Community by Ângelo Galvão (@angelogalvao).</description>
    <link>https://dev.to/angelogalvao</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1329452%2F44d939eb-55fe-4b30-99ca-03fda64b68fa.jpeg</url>
      <title>DEV Community: Ângelo Galvão</title>
      <link>https://dev.to/angelogalvao</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/angelogalvao"/>
    <language>en</language>
    <item>
      <title>Red Hat's Spring Boot application on OpenShift 4</title>
      <dc:creator>Ângelo Galvão</dc:creator>
      <pubDate>Tue, 05 Mar 2024 20:02:53 +0000</pubDate>
      <link>https://dev.to/angelogalvao/red-hats-spring-boot-application-on-openshift-4-37hm</link>
      <guid>https://dev.to/angelogalvao/red-hats-spring-boot-application-on-openshift-4-37hm</guid>
      <description>&lt;p&gt;Do you know that Red Hat offers and support its own brand of Spring Boot libraries? Do you know that Red Hat also offers libraries that makes build and deploy on OpenShift easier? &lt;/p&gt;




&lt;p&gt;&lt;em&gt;In this quick article you will learn how to build and deploy an example application on OpenShift 4!&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  First, let's review the environment and versions:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Openshift Container Platform 4.14&lt;/li&gt;
&lt;li&gt;Red Hat build of Spring Boot 2.7&lt;/li&gt;
&lt;li&gt;Java 11 &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Diclaimer
&lt;/h2&gt;

&lt;p&gt;This article expects that you have some knowledge on Spring Boot and Openshift&lt;/p&gt;

&lt;h2&gt;
  
  
  Use Red Hat libraries
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Fix your libraries
&lt;/h3&gt;

&lt;p&gt;Starting with version 2.7 of Spring Boot, instead of shipping its own version of Spring Boot libraries, Red Hat strategy is to allow the use of the same official version of Spring Boot and only override the components that Red Hat offers with its own version. &lt;br&gt;
The most notable example is the Undertow web container, which is offered on version 2.2.26.SP2-redhat-00001 at the time of this writing. This is how you override the libraries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.springframework.boot&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;spring-boot-starter-web&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;exclusions&amp;gt;&lt;/span&gt;    
        &lt;span class="c"&gt;&amp;lt;!-- Exclude the Tomcat dependency --&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;exclusion&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.springframework.boot&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;spring-boot-starter-tomcat&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/exclusion&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/exclusions&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;org.springframework.boot&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;spring-boot-starter-undertow&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;io.undertow&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;undertow-core&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;2.2.26.SP2-redhat-00001&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;scope&amp;gt;&lt;/span&gt;compile&lt;span class="nt"&gt;&amp;lt;/scope&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Visit &lt;a href="https://access.redhat.com/articles/3348731"&gt;Red Hat Spring Boot Component details page&lt;/a&gt; to a list of components and versions that overrides the provide Spring Boot libraries. &lt;/p&gt;

&lt;h3&gt;
  
  
  Include the Dekorate dependency
&lt;/h3&gt;

&lt;p&gt;The &lt;a href="//dekorate.io"&gt;dekorate.io&lt;/a&gt; is a new project that facilitates build and deploying your application on OpenShift. It uses annotations to decorate your application with OpenShift own resources. To use it, first add the dependency in the &lt;code&gt;pom.xml&lt;/code&gt; of your project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;dependency&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;groupId&amp;gt;&lt;/span&gt;io.dekorate&lt;span class="nt"&gt;&amp;lt;/groupId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;artifactId&amp;gt;&lt;/span&gt;openshift-annotations&lt;span class="nt"&gt;&amp;lt;/artifactId&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;version&amp;gt;&lt;/span&gt;2.11.5.redhat-00017&lt;span class="nt"&gt;&amp;lt;/version&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/dependency&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Annotate your application
&lt;/h3&gt;

&lt;p&gt;To take advantage of the Dekorate library, annotate your application with &lt;code&gt;@OpenshiftApplication&lt;/code&gt; annotation to configure how it will be deployed in OpenShift. In this example, the application will run 3 replicas and a Route object will be created.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nd"&gt;@SpringBootApplication&lt;/span&gt;
&lt;span class="nd"&gt;@OpenshiftApplication&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;replicas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SpringBootExampleAppApplication&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;SpringApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;SpringBootExampleAppApplication&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;class&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Set the s2i builder image
&lt;/h3&gt;

&lt;p&gt;In some clusters, the default s2i builder image is incorrectly running pods with Java 8 version instead of Java 11. To fix that, add the following property in application.properties Spring Boot file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="py"&gt;dekorate.s2i.builder-image&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;registry.access.redhat.com/ubi9/openjdk-11:latest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Finally, deploy your application
&lt;/h2&gt;

&lt;p&gt;Now, the final step is to deploy your application on Openshift. Just run the following command on the application root folder after properly login on OpenShift cluster with the &lt;code&gt;oc&lt;/code&gt; client library:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;./mvnw clean &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-Ddekorate&lt;/span&gt;.deploy&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If everything runs correctly, your application will be running on 3 pods and a be accessible from a route.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is next?
&lt;/h2&gt;

&lt;p&gt;Did you like this article? Then, visit the &lt;a href="https://github.com/angelogalvao/redhat-openshift-examples/tree/main/spring-boot-example-app"&gt;example application repository in Git Hub&lt;/a&gt; to get more details on how to build and deploy Red Hat own version of Spring Boot on Openshift 4.&lt;/p&gt;

</description>
      <category>openshift</category>
      <category>springboot</category>
      <category>redhat</category>
      <category>java</category>
    </item>
  </channel>
</rss>
