<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Deshani Palliyaguruge on Medium]]></title>
        <description><![CDATA[Stories by Deshani Palliyaguruge on Medium]]></description>
        <link>https://medium.com/@deshanipalliyaguruge2000?source=rss-9a1e7e0602bc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*9TTbk56Gc7hiKOfwkVf94A.png</url>
            <title>Stories by Deshani Palliyaguruge on Medium</title>
            <link>https://medium.com/@deshanipalliyaguruge2000?source=rss-9a1e7e0602bc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 23:35:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@deshanipalliyaguruge2000/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Sending Broadcast Notifications with WebSocket, Spring Boot, React, STOMP, and ,SockJS]]></title>
            <link>https://medium.com/@deshanipalliyaguruge2000/sending-broadcast-notifications-with-websocket-spring-boot-react-stomp-and-sockjs-50d99352c5bb?source=rss-9a1e7e0602bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/50d99352c5bb</guid>
            <dc:creator><![CDATA[Deshani Palliyaguruge]]></dc:creator>
            <pubDate>Mon, 08 Jul 2024 14:29:12 GMT</pubDate>
            <atom:updated>2024-09-02T09:19:14.587Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sending Broadcast Notifications with WebSocket, Spring Boot, React, STOMP, and SockJS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*loxBpjS8LAWhdXaOQZXSbg.png" /></figure><p>Hey there! Today, I’m going to share how you can implement real-time notifications in your web application using WebSocket, React, STOMP client, SockJS, and Spring Boot. Real-time notifications are super important for any modern web app, and I’ll show you how to handle broadcast notifications with examples. Let’s dive in!</p><h3>What Are Real-time Notifications?</h3><p>Real-time notifications are alerts or messages that appear instantly on the user’s screen without the need to refresh the page. They are essential for creating dynamic and responsive web applications. For example, when someone sends you a message on Facebook, you get a notification immediately without reloading the page. That’s a real-time notification!</p><h3>Setting Up the Project</h3><p>To get started, we need to set up both the backend and frontend of our project. Here are the tools we will use:</p><ul><li><strong>Spring Boot</strong> for the backend</li><li><strong>WebSocket</strong> for real-time communication</li><li><strong>SockJS</strong> for WebSocket fallback options</li><li><strong>STOMP</strong> (Simple Text Oriented Messaging Protocol) for messaging</li><li><strong>React</strong> for the frontend</li></ul><h3>Backend with Spring Boot</h3><p>First, let’s set up the Spring Boot application. We need to add dependencies for WebSocket and STOMP.</p><h4>Step 1: Adding Dependencies</h4><p>In your pom.xml, add the following dependencies:</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>    &lt;artifactId&gt;spring-boot-starter-websocket&lt;/artifactId&gt;<br>&lt;/dependency&gt;<br>&lt;dependency&gt;<br>    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>    &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><h4>Step 2: WebSocket Configuration</h4><p>Next, create a configuration class to set up WebSocket and STOMP.</p><p><strong>WebSocketConfig.java</strong></p><pre>package com.example.demo.config;<br><br>import org.springframework.context.annotation.Configuration;<br>import org.springframework.messaging.simp.config.MessageBrokerRegistry;<br>import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;<br>import org.springframework.web.socket.config.annotation.StompEndpointRegistry;<br>import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;<br><br>@Configuration<br>@EnableWebSocketMessageBroker<br>public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {<br><br>    @Override<br>    public void configureMessageBroker(MessageBrokerRegistry config) {<br>        config.setApplicationDestinationPrefixes(&quot;/app&quot;);<br>        config.enableSimpleBroker(&quot;/topic&quot;);<br>        <br>    }<br><br>    @Override<br>    public void registerStompEndpoints(StompEndpointRegistry registry) {<br>        registry.addEndpoint(&quot;/ws&quot;)<br>                .setAllowedOrigins(&quot;http://localhost:3000&quot;) // Allow requests from the React frontend<br>                .withSockJS();<br>    }<br>}</pre><p>In this configuration file:</p><ul><li>We enable WebSocket message handling by annotating the class with @EnableWebSocketMessageBroker.</li><li>We configure a message broker with a prefix /app for messages sent from the client to the server and /topic for messages sent from the server to the clients.</li><li>We register an endpoint /ws that will use SockJS for fallback options.</li></ul><h4>Step 3: WebSocket Controller</h4><p>Next, we need a controller to handle WebSocket messages.</p><p><strong>WebSocketController.java</strong></p><pre>package com.example.demo.controller;<br><br>import org.springframework.messaging.handler.annotation.MessageMapping;<br>import org.springframework.messaging.handler.annotation.SendTo;<br>import org.springframework.stereotype.Controller;<br>import com.example.demo.model.Greeting;<br><br>@Controller<br>public class WebSocketController {<br><br>    @MessageMapping(&quot;/hello&quot;)<br>    @SendTo(&quot;/topic/greetings&quot;)<br>    public Greeting greeting(String name) {<br>        return new Greeting(&quot;Hello, &quot; + name + &quot;!&quot;);<br>    }<br>}</pre><p>In this controller:</p><ul><li>The @MessageMapping(&quot;/hello&quot;) annotation maps messages sent to /app/hello to the greeting method.</li><li>The @SendTo(&quot;/topic/greetings&quot;) annotation ensures the returned Greeting object is sent to all subscribers of the /topic/greetings topic.</li></ul><h4>Step 4: Greeting Model</h4><p>We need a simple model to represent the greeting message.</p><p><strong>Greeting.java</strong></p><pre>package com.example.demo.model;<br><br>import lombok.AllArgsConstructor;<br>import lombok.Data;<br>import lombok.NoArgsConstructor;<br><br>@Data<br>@NoArgsConstructor<br>@AllArgsConstructor<br>public class Greeting {<br>    private String content;<br>}</pre><h4>Step 5: React Frontend</h4><p>To set up the React frontend to interact with our WebSocket server, follow these steps:</p><ol><li><strong>Create a React App</strong>: If you don’t have a React app set up already, you can create one using Create React App. Open your terminal and run:</li></ol><pre>npx create-react-app websocket-client<br>cd websocket-client</pre><p><strong>2. Install STOMP and SockJS</strong>: You’ll need the @stomp/stompjs and sockjs- client packages for WebSocket communication. Install them using npm:</p><pre>npm install @stomp/stompjs sockjs-client</pre><p><strong>3. Create the React Component</strong>: Now, create a React component that will handle the WebSocket connection and messaging.</p><p><strong>App.js</strong></p><pre>import React, { useState, useEffect, useRef } from &#39;react&#39;;<br>import SockJS from &#39;sockjs-client&#39;;<br>import { Client } from &#39;@stomp/stompjs&#39;;<br><br>const App = () =&gt; {<br>    const [message, setMessage] = useState(&#39;&#39;);<br>    const [name, setName] = useState(&#39;&#39;);<br>    const stompClientRef = useRef(null);<br><br>    useEffect(() =&gt; {<br>        const socket = new SockJS(&#39;http://localhost:8080/ws&#39;);<br>        const stompClient = new Client({<br>            webSocketFactory: () =&gt; socket,<br>            reconnectDelay: 5000,<br>            debug: (str) =&gt; {<br>                console.log(str);<br>            },<br>            onConnect: () =&gt; {<br>                console.log(&#39;Connected to WebSocket&#39;);<br>                stompClient.subscribe(&#39;/topic/greetings&#39;, (response) =&gt; {<br>                    console.log(&#39;Received message:&#39;, response.body);<br>                    setMessage(JSON.parse(response.body).content);<br>                });<br>            },<br>            onStompError: (frame) =&gt; {<br>                console.error(&#39;Broker reported error: &#39; + frame.headers[&#39;message&#39;]);<br>                console.error(&#39;Additional details: &#39; + frame.body);<br>            },<br>        });<br><br>        stompClient.activate();<br>        stompClientRef.current = stompClient;<br><br>        return () =&gt; {<br>            stompClient.deactivate();<br>        };<br>    }, []);<br><br>    const sendMessage = () =&gt; {<br>        const stompClient = stompClientRef.current;<br>        if (stompClient &amp;&amp; stompClient.connected) {<br>            console.log(&#39;Sending message:&#39;, name);<br>            stompClient.publish({<br>                destination: &#39;/app/hello&#39;,<br>                body: name,<br>            });<br>        } else {<br>            console.error(&#39;Stomp client is not connected&#39;);<br>        }<br>    };<br><br>    return (<br>        &lt;div&gt;<br>            &lt;input <br>                type=&quot;text&quot; <br>                placeholder=&quot;Enter your name&quot; <br>                value={name} <br>                onChange={(e) =&gt; setName(e.target.value)} <br>            /&gt;<br>            &lt;button onClick={sendMessage}&gt;Send&lt;/button&gt;<br>            &lt;p&gt;{message}&lt;/p&gt;<br>        &lt;/div&gt;<br>    );<br>};<br><br>export default App;</pre><p>In this React component:</p><ul><li>We use SockJS to create a WebSocket connection to our Spring Boot backend.</li><li>We use the STOMP client to handle the WebSocket communication.</li><li>The useEffect hook establishes the connection when the component mounts and cleans up when it unmounts.</li><li>We subscribe to the /topic/greetings topic to receive messages from the server.</li><li>The sendMessage function sends the name entered in the input field to the server.</li></ul><h4>How It Works Together</h4><ol><li><strong>Establish Connection</strong>: When the React component mounts, it creates a WebSocket connection to the Spring Boot server using SockJS.</li><li><strong>Subscribe to Topic</strong>: The client subscribes to the /topic/greetings topic to receive broadcast messages.</li><li><strong>Send Message</strong>: When the user enters a name and clicks the send button, the sendMessage function sends the name to the server at the /app/hello endpoint.</li><li><strong>Handle Message</strong>: The Spring Boot controller handles the message, creates a Greeting object, and sends it to the /topic/greetings topic.</li><li><strong>Receive Message</strong>: The React client receives the greeting message and updates the state to display the message on the screen.</li></ol><p>This setup allows real-time broadcast notifications to be sent from the server to all connected clients. It’s a simple and effective way to add real-time features to your application.</p><p>I hope this explanation helps you understand the workflow of sending broadcast notifications using these technologies. If you have any questions, feel free to ask!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50d99352c5bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a REST API Using Spring Boot]]></title>
            <link>https://medium.com/@deshanipalliyaguruge2000/how-to-create-a-rest-api-using-spring-boot-d696fd97eba3?source=rss-9a1e7e0602bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/d696fd97eba3</guid>
            <dc:creator><![CDATA[Deshani Palliyaguruge]]></dc:creator>
            <pubDate>Wed, 22 May 2024 10:05:41 GMT</pubDate>
            <atom:updated>2024-05-22T10:05:41.633Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E4KsnoweqQWe0DHnY4Vh-Q.png" /></figure><p>Hi guys, welcome.</p><p>In this article, I am going to go through the steps of Creating a REST API with Spring Boot. It involves a few key steps that you’ll need to understand: <strong>setting up the project, defining the entity, creating the repository, writing the service layer, and setting up the controller.</strong> Additionally, we’ll use <strong>MySQL</strong> as our database to store the data. Let’s walk through each step, explaining how data flows and what each file does.</p><h4>Step 1: Setting Up Your Spring Boot Project</h4><p>To get started, you need to set up a Spring Boot project. You can do this using <a href="https://start.spring.io/">Spring Initializr</a>. Choose the following options:</p><ul><li>Project: Maven Project</li><li>Language: Java</li><li>Spring Boot: Latest stable version</li><li>Dependencies: Spring Web, Spring Data JPA, MySQL Driver, Lombok</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NPtfzhKAM6SpbAuex5xF5g.png" /><figcaption>Spring initializer</figcaption></figure><p>Once you generate the project, download the zip file, and extract it to your desired location. Open the project in your favorite IDE (e.g., IntelliJ IDEA, Eclipse).</p><h4>Step 2: Configure MySQL Database</h4><p>First, you need to configure the database connection in the application.properties file.</p><pre># src/main/resources/application.properties<br>spring.datasource.url=jdbc:mysql://localhost:3306/your_database_name<br>spring.datasource.username=your_username<br>spring.datasource.password=your_password<br>spring.jpa.hibernate.ddl-auto=update<br>spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect</pre><p>Make sure MySQL is installed and running on your machine, and create a database for the project.</p><h4>Step 3: Define Your Entity Class</h4><p>An entity class represents a table in the database. Here’s a sample code of the Material entity:</p><pre>package com.example.store.entity;<br><br>import jakarta.persistence.*;<br>import lombok.AllArgsConstructor;<br>import lombok.Getter;<br>import lombok.NoArgsConstructor;<br>import lombok.Setter;<br><br>@Entity<br>@Table(name = &quot;materials&quot;)<br>@Getter<br>@Setter<br>@NoArgsConstructor<br>@AllArgsConstructor<br>public class Material {<br>    @Id<br>    @GeneratedValue(strategy = GenerationType.IDENTITY)<br>    private Long id;<br><br>    @Column(nullable = false)<br>    private String name;<br><br>    @Column(nullable = false)<br>    private int quantity;<br>}</pre><p>This class defines the Material entity with fields that map to columns in the materials table. The annotations help Hibernate (JPA implementation) understand how to map this class to the database table.</p><h4>Step 4: Create a DTO Class</h4><p>A DTO (Data Transfer Object) class is used to transfer data between layers. Here’s a simple MaterialDto:</p><pre>package com.example.store.dto;<br><br>import lombok.AllArgsConstructor;<br>import lombok.Getter;<br>import lombok.NoArgsConstructor;<br>import lombok.Setter;<br><br>@Getter<br>@Setter<br>@NoArgsConstructor<br>@AllArgsConstructor<br>public class MaterialDto {<br>    private Long id;<br>    private String name;<br>    private int quantity;<br>}</pre><p>This class is a plain data holder for transferring Material data between the client, controller, and service layers.</p><h4>Step 5: Create a Mapper Class</h4><p>A mapper class converts entities to DTOs and vice versa. Here’s a MaterialMapper:</p><pre>package com.example.store.mapper;<br><br>import com.example.store.dto.MaterialDto;<br>import com.example.store.entity.Material;<br><br>public class MaterialMapper {<br>    public static MaterialDto toDto(Material material) {<br>        return new MaterialDto(material.getId(), material.getName(), material.getQuantity());<br>    }<br><br>    public static Material toEntity(MaterialDto materialDto) {<br>        return new Material(materialDto.getId(), materialDto.getName(), materialDto.getQuantity());<br>    }<br>}</pre><p>his class provides static methods to map between Material entities and MaterialDto objects.</p><h4>Step 6: Create a Repository Interface</h4><p>The repository interface is used to interact with the database. Here’s a simple MaterialRepository:</p><pre>package com.example.store.repository;<br><br>import com.example.store.entity.Material;<br>import org.springframework.data.jpa.repository.JpaRepository;<br><br>public interface MaterialRepository extends JpaRepository&lt;Material, Long&gt; {<br>}</pre><p>This interface extends JpaRepository, providing CRUD operations for the Material entity without needing to write any SQL queries. Spring Data JPA handles it for you.</p><h4>Step 7: Write a Service Class</h4><p>The service class contains the business logic. Here’s a MaterialService for creating a material:</p><pre>package com.example.store.service;<br><br>import com.example.store.dto.MaterialDto;<br>import com.example.store.entity.Material;<br>import com.example.store.mapper.MaterialMapper;<br>import com.example.store.repository.MaterialRepository;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.stereotype.Service;<br><br>@Service<br>public class MaterialService {<br>    @Autowired<br>    private MaterialRepository materialRepository;<br><br>    public MaterialDto createMaterial(MaterialDto materialDto) {<br>        Material material = MaterialMapper.toEntity(materialDto);<br>        Material savedMaterial = materialRepository.save(material);<br>        return MaterialMapper.toDto(savedMaterial);<br>    }<br>}</pre><ul><li>This service class uses the MaterialRepository to save a new Material to the database. It contains business logic, making it a good place to handle validations or additional computations. The createMaterial method maps the DTO to an entity, saves it, and maps the saved entity back to a DTO.</li></ul><h4>Step 8: Create a Controller Class</h4><p>The controller class handles HTTP requests. Here’s the MaterialController with an endpoint for creating a material:</p><pre>package com.example.store.controller;<br><br>import com.example.store.dto.MaterialDto;<br>import com.example.store.service.MaterialService;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.http.HttpStatus;<br>import org.springframework.http.ResponseEntity;<br>import org.springframework.web.bind.annotation.*;<br><br>@RestController<br>@RequestMapping(&quot;/api/materials&quot;)<br>public class MaterialController {<br>    @Autowired<br>    private MaterialService materialService;<br><br>    @PostMapping<br>    public ResponseEntity&lt;MaterialDto&gt; createMaterial(@RequestBody MaterialDto materialDto) {<br>        MaterialDto savedMaterial = materialService.createMaterial(materialDto);<br>        return new ResponseEntity&lt;&gt;(savedMaterial, HttpStatus.CREATED);<br>    }<br>}</pre><p>This controller class exposes RESTful endpoints. The @PostMapping annotation maps HTTP POST requests to the createMaterial method. The method receives a MaterialDto object from the request body, passes it to the MaterialService, and returns the saved material DTO with a 201 Created status.</p><h4>Step 9: Run Your Application</h4><p>With everything set up, you can run your Spring Boot application. In your IDE, right-click on the main class (the one with @SpringBootApplication) and choose &quot;Run&quot;. Alternatively, you can use the command line:</p><pre>mvn spring-boot:run</pre><h3>Data Flow Explanation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_p8gnnNNvzn7BziM_aIFWA.png" /></figure><ol><li>Client Request: A client (e.g., Postman, a frontend application) sends an HTTP POST request to the /api/materials endpoint with the material data in the request body.</li><li>Controller Layer: The MaterialController receives the request. The createMaterial method is called with the material data. The controller delegates the task of creating the material to the MaterialService.</li><li>Service Layer: The MaterialService processes the request. It uses MaterialMapper to convert the MaterialDto to a Material entity and then calls the MaterialRepository to save the material data into the database.</li><li>Repository Layer: The MaterialRepository interacts with the database. It uses JPA to save the Material entity, which Hibernate translates into an SQL INSERT statement to store the data in the materials table.</li><li>Database: The MySQL database stores the material data in the materials table. After successful insertion, the database returns the saved material entity to the repository.</li><li>Service Layer: The MaterialService converts the saved Material entity back to a MaterialDto using the MaterialMapper.</li><li>Response: The MaterialService returns the saved material DTO to the controller, which then sends it back to the client as the HTTP response.</li></ol><h3>Conclusion</h3><p>Congratulations! You’ve just created a simple REST API using Spring Boot with MySQL as the database. We covered the basics of setting up a Spring Boot project, defining an entity, creating a DTO and a mapper, creating a repository, writing a service, and creating a controller. This guide serves as a starting point, and you can expand it by adding more endpoints, validations, exception handling, and security features.</p><p>Spring Boot makes it easy to develop robust and scalable REST APIs. Keep experimenting and exploring its features to build more complex applications. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d696fd97eba3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Folder Structure of a Spring Boot Project]]></title>
            <link>https://medium.com/@deshanipalliyaguruge2000/understanding-the-folder-structure-of-a-spring-boot-project-7f213fed5699?source=rss-9a1e7e0602bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f213fed5699</guid>
            <dc:creator><![CDATA[Deshani Palliyaguruge]]></dc:creator>
            <pubDate>Fri, 17 May 2024 10:46:47 GMT</pubDate>
            <atom:updated>2024-05-17T10:46:47.643Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HnkuwHveNlcV1l3y6p1Kqw.png" /></figure><p>Hello guys! Welcome to my first blog post.</p><p>Spring Boot is a powerful framework that simplifies the development of Java applications. One of its key features is the opinionated approach to configuration, which includes a predefined project structure. Understanding this structure is essential for efficient development and maintenance of Spring Boot applications. In this article, we’ll explore the default folder structure of a Spring Boot project, explain the purpose of each folder, and provide best practices for maintaining an organized project.</p><h3>Introduction to Spring Boot</h3><p>Spring Boot is designed to make it easy to create stand-alone, production-grade Spring-based applications. It takes an opinionated view of the Spring platform, which means it comes with sensible defaults out of the box. This approach significantly reduces the amount of configuration and boilerplate code developers need to write.</p><h3>Default Folder Structure</h3><p>When you create a new Spring Boot project, either through the Spring Initializr or using your IDE, you’ll notice a standard folder structure. Here’s a breakdown of the default structure and the purpose of each folder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*HanSwTLHN38POny7UfeN5w.png" /><figcaption>Folder structure of a spring boot project</figcaption></figure><h3>1. src/main/java</h3><p>This is the main source folder where your application code resides. Typically, it includes:</p><ul><li><strong>com.Ascendia.server:</strong> The base package for your application. It’s a best practice to use a reverse domain name for the base package (e.g.,com.Ascendia.server).</li><li><strong>Application Class:</strong> This class contains the main method that bootstraps the Spring Boot application. For example:</li></ul><pre>package com.Ascendia.server;<br><br>import org.springframework.boot.SpringApplication;<br>import org.springframework.boot.autoconfigure.SpringBootApplication;<br><br>@SpringBootApplication<br>public class ServerApplication {<br><br> public static void main(String[] args) {<br>  SpringApplication.run(ServerApplication.class, args);<br> }<br><br>}</pre><h3>2. src/main/resources</h3><p>This folder contains application resources such as configuration files and static assets. Key subfolders and files include:</p><ul><li><strong>application.properties or application.yml:</strong> The primary configuration file for your Spring Boot application. You can define various properties such as database configurations, server ports, etc.</li><li><strong>static:</strong> Contains static resources such as HTML, CSS, and JavaScript files.</li><li><strong>templates: </strong>Holds template files (e.g., Thymeleaf or FreeMarker templates) used by the web layer.</li><li><strong>META-INF/resources:</strong> This folder is used for adding resources that are typically served by the container itself.</li></ul><h3>3. src/test/java</h3><p>This is where your test code resides. It mirrors the structure of src/main/java and includes test classes and methods. Spring Boot provides strong support for testing, including integration tests, which can be placed here.</p><h3>4. pom.xml or build.gradle</h3><p>These are the build configuration files for Maven and Gradle, respectively. They manage project dependencies, plugins, and other build-related configurations.</p><h3>Customizing the Structure</h3><p>While the default structure is suitable for most applications, there might be scenarios where you need to customize it. For example, you might want to add new directories for specific purposes, such as src/main/resources/db/migration for database migration scripts.</p><p>To customize the structure, you can adjust your build configuration (Maven or Gradle) accordingly. Here’s an example of customizing the resource directory in pom.xml:</p><pre>&lt;build&gt;<br>    &lt;resources&gt;<br>        &lt;resource&gt;<br>            &lt;directory&gt;src/main/custom-resources&lt;/directory&gt;<br>        &lt;/resource&gt;<br>    &lt;/resources&gt;<br>&lt;/build&gt;</pre><h3>Best Practices for Maintaining an Organized Project</h3><ol><li>Follow Standard Conventions: Stick to the default structure as much as possible to ensure consistency and maintainability.</li><li>Group Related Files: Keep related classes and resources together. For example, place all repository interfaces in a repository package.</li><li>Modularize Your Code: If your project grows large, consider breaking it into modules to manage complexity.</li><li>Keep Configuration Manageable: Use profiles (e.g., application-dev.properties, application-prod.properties) to manage environment-specific configurations.</li></ol><h3>Conclusion</h3><p>Understanding and maintaining a well-organized folder structure is crucial for the development and maintenance of Spring Boot applications. The default structure provided by Spring Boot is designed to be intuitive and efficient, helping developers to focus on writing code rather than managing configuration.</p><p>By following the standard conventions and best practices outlined in this article, you’ll be able to create clean, maintainable, and scalable Spring Boot applications. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f213fed5699" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>