<?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: Padmanabhan M</title>
    <description>The latest articles on DEV Community by Padmanabhan M (@padmanabhanm).</description>
    <link>https://dev.to/padmanabhanm</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%2F212359%2F1451d9b6-68e8-43d0-b136-5d15cf9a300b.jpeg</url>
      <title>DEV Community: Padmanabhan M</title>
      <link>https://dev.to/padmanabhanm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/padmanabhanm"/>
    <language>en</language>
    <item>
      <title>Spring Boot — Getting Started</title>
      <dc:creator>Padmanabhan M</dc:creator>
      <pubDate>Tue, 23 Jun 2020 16:56:06 +0000</pubDate>
      <link>https://dev.to/padmanabhanm/spring-boot-getting-started-5643</link>
      <guid>https://dev.to/padmanabhanm/spring-boot-getting-started-5643</guid>
      <description>&lt;p&gt;Spring boot is one of the popular Java framework, which under the hood comprises of multiple Spring based Java projects at its core. Spring boot helps to get started with stand-alone Spring based applications with minimal coding.&lt;/p&gt;

&lt;p&gt;Spring boot provides an Embedded Tomcat, Jetty or Undertow runtime environments for the jar/war to run as stand-alone applications along with many other useful features.&lt;/p&gt;

&lt;p&gt;Web applications are developed at a faster phase using Spring boot owing to its inherent support for simplifying web development.&lt;/p&gt;

&lt;p&gt;Let’s create an web application hosting an API end point with returns the text &lt;strong&gt;&lt;em&gt;Hello World !!&lt;/em&gt;&lt;/strong&gt; as the response.&lt;/p&gt;

&lt;h2&gt;
  
  
  Spring Initilizr
&lt;/h2&gt;

&lt;p&gt;The starter website (&lt;a href="https://start.spring.io/"&gt;https://start.spring.io/&lt;/a&gt;) helps to add dependencies and make additional configuration through an interactive interface.&lt;/p&gt;

&lt;p&gt;The options selected for generating this project is shown below in the image.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H1MtJhyK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/eseyfy48p1wjtf29wb62.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H1MtJhyK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/eseyfy48p1wjtf29wb62.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Spring Web&lt;/em&gt;&lt;/strong&gt; is the only dependency that is required to get started. &lt;em&gt;Sweet isn’t it !!!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can click on &lt;strong&gt;&lt;em&gt;Expolore&lt;/em&gt;&lt;/strong&gt; to see the file structure which will be downloaded. Clicking on &lt;strong&gt;&lt;em&gt;Generate&lt;/em&gt;&lt;/strong&gt; button downloads a &lt;em&gt;.zip&lt;/em&gt; file which contains all the boiler plate files needed to run the code.&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;pom.xml&lt;/em&gt; should look similar to this&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h2&gt;
  
  
  IDE
&lt;/h2&gt;

&lt;p&gt;My preferred choice of IDE is IntelliJ, other IDE’s like Eclipse, NetBeans, etc. are also good enough to get started. After extracting the zip file the Maven project can now be imported into the IDE.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre Requisites
&lt;/h2&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* Java 11
* Maven
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Digging In
&lt;/h2&gt;

&lt;p&gt;Once you have imported the project to an IDE the project structure looks similar to this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VFeUx5ok--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bfubhwikpqoa6hiiensu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VFeUx5ok--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bfubhwikpqoa6hiiensu.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;src/&lt;/em&gt; contains the source code along with resources and tests&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;main/&lt;/em&gt; contains the actual source code and additional resources&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;test/&lt;/em&gt; contains the test cases and test suites&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The main method is placed in the file&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`SpringBootHelloWorldApplication.java`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;which gets executed upon starting the application. The &lt;strong&gt;&lt;em&gt;@SpringBootApplication&lt;/em&gt;&lt;/strong&gt; annotation abstracts a lot ( (╯°□°)╯︵ ┻━┻ ) of the default configurations which otherwise needs to be set up for the web app to run.&lt;/p&gt;
&lt;h2&gt;
  
  
  First Light
&lt;/h2&gt;

&lt;p&gt;Now lets create our first API end point. Create a class named&lt;/p&gt;

&lt;p&gt;&lt;code&gt;HelloWorldController.java&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and add the following piece of code to it&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h2&gt;
  
  
  Explanation
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;@RestController — a special annotation which says that this class contains the terminating end points, in this case /hello&lt;/p&gt;

&lt;p&gt;@GetMapping — this annotation is written on top of a method which needs to be executed when /hello is requested from the client through the GET HTTP verb&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The method &lt;em&gt;helloWorld()&lt;/em&gt; is executed when /hello is encountered from the client and it returns a text as response in this case &lt;strong&gt;&lt;em&gt;Hello World !!!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Witness the Magic
&lt;/h2&gt;

&lt;p&gt;Now that we have written our first API end point, let’s build our Spring boot application. The build command used with the Maven build is&lt;/p&gt;

&lt;p&gt;&lt;code&gt;mvn clean compile package -DskipTests&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We are skipping the tests for now. After a successful build the executable jar would be generated in the &lt;strong&gt;&lt;em&gt;target/helloworld-0.0.1-SNAPSHOT.jar&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s run the executable using the command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;java -jar target/helloworld-0.0.1-SNAPSHOT.jar&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;from the project directory and lets witness the magic&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3sPivuF_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5nhggri736weri599nn4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3sPivuF_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/5nhggri736weri599nn4.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On closer observation of the logs written to the console we understand that the process is running on the port 8080 (it’s configurable of course)&lt;/p&gt;

&lt;p&gt;Now that our web application is up and running on port 8080 lets see what happens when we visit the url &lt;a href="http://localhost:8080/hello"&gt;http://localhost:8080/hello&lt;/a&gt; on a web browser.&lt;/p&gt;

&lt;p&gt;You should be able to see&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oEpyRNPg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/uplpu5r1igyu4gq89cuk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oEpyRNPg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/uplpu5r1igyu4gq89cuk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;and Ta-Daaaa !!!! We just wrote our first API endpoint using Spring boot with minimal configuration and setup.&lt;/p&gt;

</description>
      <category>java</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
