<?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: Arikaran S</title>
    <description>The latest articles on DEV Community by Arikaran S (@arikaran).</description>
    <link>https://dev.to/arikaran</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%2F1511191%2F63a20784-9fd0-4465-bb69-ed108da82d27.jpg</url>
      <title>DEV Community: Arikaran S</title>
      <link>https://dev.to/arikaran</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arikaran"/>
    <language>en</language>
    <item>
      <title>Getting started with Spring boot</title>
      <dc:creator>Arikaran S</dc:creator>
      <pubDate>Sat, 25 May 2024 07:03:22 +0000</pubDate>
      <link>https://dev.to/arikaran/getting-started-with-spring-boot-28gc</link>
      <guid>https://dev.to/arikaran/getting-started-with-spring-boot-28gc</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Spring Boot is a Java framework used for backend development. It's popular for enabling the rapid development of production-ready web applications with minimal configuration.&lt;/p&gt;

&lt;p&gt;Spring Boot provides numerous built-in libraries for various technologies, such as messaging, security, etc., making it exceptionally easy to use. While it's commonly utilized in microservice architecture, it's also applicable in monolithic architecture setups.&lt;/p&gt;

&lt;p&gt;There are several advantages to using Spring Boot that contribute to its status as a leading framework:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Auto-configuration&lt;/strong&gt;: By simply adding the .jar file as a dependency in our Spring project, Spring handles most configurations automatically. If needed, we can override or exclude auto-configuration for specific libraries. For example, configurations for web servers, security, databases, etc., are managed effortlessly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Starter dependencies&lt;/strong&gt;: Spring Boot offers many starter dependencies, simplifying the integration of new technologies. This avoids the need for manual integration.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Actuator support&lt;/strong&gt;: In complex applications, monitoring can be challenging. Spring Boot addresses this with built-in support called Actuator. Actuator provides endpoints to check the health of the application, facilitating easier monitoring, especially in applications integrating with various third-party services and databases.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Embedded web servers&lt;/strong&gt;: Spring Boot includes embedded web servers, making it effortless to develop and deploy applications. Without embedded servers, deploying to external web servers would require writing extensive XML configurations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Large community&lt;/strong&gt;: Spring Boot boasts a vast community, which significantly eases the developer's life. If stuck, there's ample support available.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Project setup
&lt;/h2&gt;

&lt;p&gt;Setting up your first Spring Boot project is straightforward:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open your favorite browser and search for &lt;a href="https://start.spring.io/"&gt;Spring Initializer&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fill in the group, artifact name, package name, select packaging type as JAR, and choose dependencies like Spring Web.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhkmkbir5kulumbq5vjpc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhkmkbir5kulumbq5vjpc.png" alt="Project setup" width="800" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click "Generate Project" to download the zip file, which contains your project. Open it in your preferred IDE (e.g., STS, IntelliJ).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once your project is open, you'll see the following folder structure:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw278ikfl7nhhaajhiwrq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw278ikfl7nhhaajhiwrq.png" alt="Project folder structure" width="800" height="462"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;src&lt;/strong&gt;: Divided into two subfolders: "main" and "test".

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;main&lt;/strong&gt;: Development code resides here. Configuration files and resources can be added to the "resources" subfolder.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;test&lt;/strong&gt;: Contains all test code.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;pom.xml&lt;/strong&gt;: This file manages dependencies of our app and their versions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The entry point of the application is the class annotated with &lt;code&gt;@SpringBootApplication&lt;/code&gt;, which contains the main method:&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="kn"&gt;package&lt;/span&gt; &lt;span class="nn"&gt;com.example.demo&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.SpringApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;org.springframework.boot.autoconfigure.SpringBootApplication&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

&lt;span class="nd"&gt;@SpringBootApplication&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;DemoApplication&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;DemoApplication&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;p&gt;&lt;strong&gt;@SpringBootApplication&lt;/strong&gt; indicates that Spring scans all packages of this class and its subclasses for configurations and components. It also enables auto-configuration, scanning all dependencies added in the pom.xml file.&lt;/p&gt;

&lt;h2&gt;
  
  
  To print "Hello, World!":
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Create a package under &lt;code&gt;src/main&lt;/code&gt; named "controller".&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a Java class named &lt;code&gt;DummyController.java&lt;/code&gt; under &lt;code&gt;src/main/controller&lt;/code&gt; and annotate it with &lt;code&gt;@RestController&lt;/code&gt; (indicating to Spring Boot that it will handle web requests and responses).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Write a simple HTTP GET request that returns a string, such as "Hello, World!".&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then start the application and make a GET request using the configured endpoint:&lt;a href="http://localhost:8080/test"&gt;http://localhost:8080/test&lt;/a&gt;, it will returns the string as response:  Hello world&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ref&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft2cxu2oqisuopajpgats.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft2cxu2oqisuopajpgats.png" alt="DummyController.java" width="800" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;"Thank you for taking the time to explore this blog. I hope this guide has been helpful in understanding how to get started with Spring Boot. Happy coding!&lt;/p&gt;

&lt;p&gt;For more technical blogs, visit &lt;a href="https://arikaran.com/"&gt;https://arikaran.com/&lt;/a&gt;"&lt;/p&gt;

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