{"id":198,"date":"2022-10-12T20:05:59","date_gmt":"2022-10-12T20:05:59","guid":{"rendered":"https:\/\/valerio.nu\/?p=198"},"modified":"2022-10-12T20:06:00","modified_gmt":"2022-10-12T20:06:00","slug":"getting-started-with-spring-boot-building-a-hello-world-application","status":"publish","type":"post","link":"https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/","title":{"rendered":"Getting started with Spring Boot building a Hello World Application"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>Introduction<\/strong><\/h2>\n\n\n\n<p>In this tutorial, our focus is to start a beginner series using Spring Boot. This particular tutorial will cover creating a Spring Boot application using Maven. That said, let us understand what Spring Boot is.<\/p>\n\n\n\n<p><strong>Getting started with Spring Boot.<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/spring.io\/projects\/spring-boot\">Spring Boot<\/a> represents a way to create applications that conform to the proper separation of concerns. It integrates various technologies and ensures that projects are delivered quickly. Spring Boot projects are easily created using <a href=\"https:\/\/start.spring.io\/\">Spring Initializr<\/a>. <\/p>\n\n\n\n<p>Spring Initializr helps get multiple components needed to develop a spring boot application as quickly as possible. A central repository called Maven manages all dependencies and other specified project configurations.\u00a0<\/p>\n\n\n\n<p>In this tutorial, we would focus on developing a simple Hello World program using Spring Boot and Thymeleaf to manage the front end. <a href=\"https:\/\/www.thymeleaf.org\/\">Thymeleaf<\/a> provides a way to present HTML in a dynamic form.&nbsp;<\/p>\n\n\n\n<p><strong>General Requirements<\/strong><\/p>\n\n\n\n<p>To get started with our development, the following system requirements are necessary:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>JDK 1.8 or above<\/li><li>Maven 3.2 or above<\/li><li>Thymeleaf<\/li><li>Spring Boot<\/li><\/ol>\n\n\n\n<p><strong>Annotations and their functions<\/strong><\/p>\n\n\n\n<p>In Spring Boot, annotations represent metadata that provides information about a program. It is a way of providing brief but vital information about components. Annotations are not a critical part of the application but are very intelligent additions that make it easier for code interpretation. In this tutorial, we used several annotations but we will not go into detail about them as this is simply a beginner series. However, we must add that annotations start with an \u201c@\u201d symbol.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Developing our Hello World Program in easy steps<\/strong><\/h2>\n\n\n\n<p><strong>Setting everything up<\/strong><br>Using our <a href=\"https:\/\/start.spring.io\/\">Spring Initializr<\/a> to get the basic structure needed for our application. The parent dependency is our spring boot code.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;parent&gt;\n\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n\t\t&lt;artifactId&gt;spring-boot-starter-parent&lt;\/artifactId&gt;\n\t\t&lt;version&gt;2.7.4&lt;\/version&gt;\n&lt;\/parent&gt;\n<\/code><\/pre>\n\n\n\n<p>Our Thymeleaf and other dependencies used in the project include<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependencies&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;\/artifactId&gt;\n\t\t&lt;\/dependency&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;spring-boot-starter-web&lt;\/artifactId&gt;\n\t\t&lt;\/dependency&gt;\n\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.springframework.boot&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;spring-boot-starter-test&lt;\/artifactId&gt;\n\t\t\t&lt;scope&gt;test&lt;\/scope&gt;\n\t\t&lt;\/dependency&gt;\n\t&lt;\/dependencies&gt;\n<\/code><\/pre>\n\n\n\n<p>Putting our components together, we have the controllers as follows:<\/p>\n\n\n\n<p>The main controller which has the configuration<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@SpringBootApplication\npublic class HelloWorldApplication {\n\n\tpublic static void main(String&#91;] args) {\n\t\tSpringApplication.run(HelloWorldApplication.class, args);\n\t}\n\n}\nFrom the above, the @SpringBootApplication is an annotation that bundles everything needed to get our spring boot project started.\n<\/code><\/pre>\n\n\n\n<p>The Helloworld class code is also shown below<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Controller\npublic class HelloSpring {\n    String Message;\n\n    @GetMapping(\"\/\")\n    public String GetHello(Model model){\n        Message = \"Hello World\";\n        model.addAttribute(\"Message\", Message);\n\n        return \"hello\";\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>Our Html (frontend) serving page sample code is shown here<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE HTML&gt;\n&lt;html lang=\"en\" xmlns:th=\"http:\/\/www.thymeleaf.org\"&gt;\n&lt;head&gt;\n  &lt;meta charset=\"utf-8\"&gt;\n  &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1, shrink-to-fit=no\"&gt;\n  &lt;title&gt;Spring Boot Thymeleaf Hello World Example&lt;\/title&gt;\n  &lt;link rel=\"stylesheet\" th:href=\"@{webjars\/bootstrap\/4.2.1\/css\/bootstrap.min.css}\"\/&gt;\n  &lt;link rel=\"stylesheet\" th:href=\"@{\/css\/main.css}\"\/&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;main role=\"main\" class=\"container\"&gt;\n  &lt;div class=\"starter-template\"&gt;\n    &lt;p&gt; &lt;span th:text=\"${Message}\"&gt; &lt;\/span&gt; Welcome to Our Getting Started tutorial.&lt;\/p&gt;\n  &lt;\/div&gt;\n&lt;\/main&gt;\n&lt;script type=\"text\/javascript\" th:src=\"@{webjars\/bootstrap\/4.2.1\/js\/bootstrap.min.js}\"&gt;&lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/code><\/pre>\n\n\n\n<p>Conclusively,&nbsp;our program is able to show how to implement a Hello world application using Spring Boot. The complete source code for this project is available on our <a href=\"https:\/\/github.com\/valerio-nu\/springboot_helloworld\">GitHub Page<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this tutorial, our focus is to start a beginner series using Spring Boot. This particular tutorial will cover creating a Spring Boot application [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-198","post","type-post","status-publish","format-standard","hentry","category-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Getting started with Spring Boot building a Hello World Application - Andy&#039;s blog \u2935\ufe0f<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting started with Spring Boot building a Hello World Application - Andy&#039;s blog \u2935\ufe0f\" \/>\n<meta property=\"og:description\" content=\"Introduction In this tutorial, our focus is to start a beginner series using Spring Boot. This particular tutorial will cover creating a Spring Boot application [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/\" \/>\n<meta property=\"og:site_name\" content=\"Andy&#039;s blog \u2935\ufe0f\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-12T20:05:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-12T20:06:00+00:00\" \/>\n<meta name=\"author\" content=\"andy\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"andy\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/10\\\/12\\\/getting-started-with-spring-boot-building-a-hello-world-application\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/10\\\/12\\\/getting-started-with-spring-boot-building-a-hello-world-application\\\/\"},\"author\":{\"name\":\"andy\",\"@id\":\"https:\\\/\\\/valerio.nu\\\/#\\\/schema\\\/person\\\/da69cc3da309893b0d3bc8fcef75f128\"},\"headline\":\"Getting started with Spring Boot building a Hello World Application\",\"datePublished\":\"2022-10-12T20:05:59+00:00\",\"dateModified\":\"2022-10-12T20:06:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/10\\\/12\\\/getting-started-with-spring-boot-building-a-hello-world-application\\\/\"},\"wordCount\":365,\"commentCount\":0,\"articleSection\":[\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/10\\\/12\\\/getting-started-with-spring-boot-building-a-hello-world-application\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/10\\\/12\\\/getting-started-with-spring-boot-building-a-hello-world-application\\\/\",\"url\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/10\\\/12\\\/getting-started-with-spring-boot-building-a-hello-world-application\\\/\",\"name\":\"Getting started with Spring Boot building a Hello World Application - Andy&#039;s blog \u2935\ufe0f\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/valerio.nu\\\/#website\"},\"datePublished\":\"2022-10-12T20:05:59+00:00\",\"dateModified\":\"2022-10-12T20:06:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/valerio.nu\\\/#\\\/schema\\\/person\\\/da69cc3da309893b0d3bc8fcef75f128\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/10\\\/12\\\/getting-started-with-spring-boot-building-a-hello-world-application\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/10\\\/12\\\/getting-started-with-spring-boot-building-a-hello-world-application\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/2022\\\/10\\\/12\\\/getting-started-with-spring-boot-building-a-hello-world-application\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/valerio.nu\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Getting started with Spring Boot building a Hello World Application\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/valerio.nu\\\/#website\",\"url\":\"https:\\\/\\\/valerio.nu\\\/\",\"name\":\"Andy&#039;s blog \u2935\ufe0f\",\"description\":\"Abandon all hope, ye who enter here\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/valerio.nu\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/valerio.nu\\\/#\\\/schema\\\/person\\\/da69cc3da309893b0d3bc8fcef75f128\",\"name\":\"andy\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4852a025c6250c852814d4017f646677730a23c1ec14eb5ca36b69dcce5135a5?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4852a025c6250c852814d4017f646677730a23c1ec14eb5ca36b69dcce5135a5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4852a025c6250c852814d4017f646677730a23c1ec14eb5ca36b69dcce5135a5?s=96&d=mm&r=g\",\"caption\":\"andy\"},\"sameAs\":[\"https:\\\/\\\/valerio.nu\"],\"url\":\"https:\\\/\\\/valerio.nu\\\/index.php\\\/author\\\/giuseppe\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Getting started with Spring Boot building a Hello World Application - Andy&#039;s blog \u2935\ufe0f","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/","og_locale":"en_US","og_type":"article","og_title":"Getting started with Spring Boot building a Hello World Application - Andy&#039;s blog \u2935\ufe0f","og_description":"Introduction In this tutorial, our focus is to start a beginner series using Spring Boot. This particular tutorial will cover creating a Spring Boot application [&hellip;]","og_url":"https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/","og_site_name":"Andy&#039;s blog \u2935\ufe0f","article_published_time":"2022-10-12T20:05:59+00:00","article_modified_time":"2022-10-12T20:06:00+00:00","author":"andy","twitter_card":"summary_large_image","twitter_misc":{"Written by":"andy","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/#article","isPartOf":{"@id":"https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/"},"author":{"name":"andy","@id":"https:\/\/valerio.nu\/#\/schema\/person\/da69cc3da309893b0d3bc8fcef75f128"},"headline":"Getting started with Spring Boot building a Hello World Application","datePublished":"2022-10-12T20:05:59+00:00","dateModified":"2022-10-12T20:06:00+00:00","mainEntityOfPage":{"@id":"https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/"},"wordCount":365,"commentCount":0,"articleSection":["Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/","url":"https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/","name":"Getting started with Spring Boot building a Hello World Application - Andy&#039;s blog \u2935\ufe0f","isPartOf":{"@id":"https:\/\/valerio.nu\/#website"},"datePublished":"2022-10-12T20:05:59+00:00","dateModified":"2022-10-12T20:06:00+00:00","author":{"@id":"https:\/\/valerio.nu\/#\/schema\/person\/da69cc3da309893b0d3bc8fcef75f128"},"breadcrumb":{"@id":"https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/valerio.nu\/index.php\/2022\/10\/12\/getting-started-with-spring-boot-building-a-hello-world-application\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/valerio.nu\/"},{"@type":"ListItem","position":2,"name":"Getting started with Spring Boot building a Hello World Application"}]},{"@type":"WebSite","@id":"https:\/\/valerio.nu\/#website","url":"https:\/\/valerio.nu\/","name":"Andy&#039;s blog \u2935\ufe0f","description":"Abandon all hope, ye who enter here","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/valerio.nu\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/valerio.nu\/#\/schema\/person\/da69cc3da309893b0d3bc8fcef75f128","name":"andy","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4852a025c6250c852814d4017f646677730a23c1ec14eb5ca36b69dcce5135a5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4852a025c6250c852814d4017f646677730a23c1ec14eb5ca36b69dcce5135a5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4852a025c6250c852814d4017f646677730a23c1ec14eb5ca36b69dcce5135a5?s=96&d=mm&r=g","caption":"andy"},"sameAs":["https:\/\/valerio.nu"],"url":"https:\/\/valerio.nu\/index.php\/author\/giuseppe\/"}]}},"_links":{"self":[{"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/posts\/198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/comments?post=198"}],"version-history":[{"count":5,"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/posts\/198\/revisions"}],"predecessor-version":[{"id":205,"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/posts\/198\/revisions\/205"}],"wp:attachment":[{"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/media?parent=198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/categories?post=198"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/valerio.nu\/index.php\/wp-json\/wp\/v2\/tags?post=198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}