{"id":33003,"date":"2024-11-01T09:13:03","date_gmt":"2024-11-01T09:13:03","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33003"},"modified":"2024-11-01T11:29:25","modified_gmt":"2024-11-01T11:29:25","slug":"spring-boot-backend-development-course-configuring-the-main-directory","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33003\/","title":{"rendered":"Spring Boot Backend Development Course, Configuring the Main Directory"},"content":{"rendered":"<p><body><\/p>\n<p>\n    Spring Boot is a Java-based framework that helps developers build applications easily without complex configurations. This course will cover how to structure the <code>main<\/code> directory of a Spring Boot project. This directory serves as the starting point for a Java application and is where the important business logic is implemented.\n<\/p>\n<h2>Spring Boot Project Structure<\/h2>\n<p>\n    A Spring Boot project follows a predefined structure. When you create a Spring Boot project in your IDE, a basic structure like the one below is generated.\n<\/p>\n<pre>\nsrc\n\u251c\u2500\u2500 main\n\u2502   \u251c\u2500\u2500 java\n\u2502   \u2502   \u2514\u2500\u2500 com\n\u2502   \u2502       \u2514\u2500\u2500 example\n\u2502   \u2502           \u2514\u2500\u2500 demo\n\u2502   \u2502               \u251c\u2500\u2500 DemoApplication.java\n\u2502   \u2502               \u2514\u2500\u2500 controller\n\u2502   \u2502               \u2514\u2500\u2500 service\n\u2502   \u2502               \u2514\u2500\u2500 repository\n\u2502   \u2514\u2500\u2500 resources\n\u2502       \u251c\u2500\u2500 application.properties\n\u2502       \u2514\u2500\u2500 static\n\u2502       \u2514\u2500\u2500 templates\n\u2514\u2500\u2500 test\n    \u2514\u2500\u2500 java\n<\/pre>\n<h2>1. src\/main\/java Directory<\/h2>\n<p>\nThe <code>src\/main\/java<\/code> directory is where the actual Java source code is located, and each package and class file is stored here. In Spring Boot, packages are generally structured in the format of <code>com.example.demo<\/code>.\n<\/p>\n<h3>1.1 Main Application Class<\/h3>\n<p>\nThe <code>DemoApplication.java<\/code> file is the entry point of the Spring Boot application. This class is annotated with <code>@SpringBootApplication<\/code>, which encompasses the following three functionalities:\n<\/p>\n<ul>\n<li><code>@Configuration<\/code>: A Java-based configuration class.<\/li>\n<li><code>@EnableAutoConfiguration<\/code>: Enables Spring Boot&#8217;s auto-configuration feature.<\/li>\n<li><code>@ComponentScan<\/code>: Automatically scans the specified packages to discover Spring components.<\/li>\n<\/ul>\n<p>Below is an example of the main application class.<\/p>\n<pre>\npackage com.example.demo;\n\nimport org.springframework.boot.SpringApplication;\nimport org.springframework.boot.autoconfigure.SpringBootApplication;\n\n@SpringBootApplication\npublic class DemoApplication {\n    public static void main(String[] args) {\n        SpringApplication.run(DemoApplication.class, args);\n    }\n}\n<\/pre>\n<h3>1.2 Package Structure<\/h3>\n<p>\n    When there are many source files, defining an appropriate package structure is important. Typically, packages such as <code>controller<\/code>, <code>service<\/code>, and <code>repository<\/code> are defined.\n<\/p>\n<h4>Controller Package<\/h4>\n<p>\nThe <code>controller<\/code> package contains methods that handle requests and return responses. In a RESTful API, the <code>@RestController<\/code> annotation is mainly used to set up the REST API server.\n<\/p>\n<pre>\npackage com.example.demo.controller;\n\nimport org.springframework.web.bind.annotation.GetMapping;\nimport org.springframework.web.bind.annotation.RestController;\n\n@RestController\npublic class HelloController {\n    @GetMapping(\"\/hello\")\n    public String sayHello() {\n        return \"Hello, World!\";\n    }\n}\n<\/pre>\n<h4>Service Package<\/h4>\n<p>\nThe <code>service<\/code> package includes classes that handle business logic. The classes here are registered in the Spring context using the <code>@Service<\/code> annotation.\n<\/p>\n<pre>\npackage com.example.demo.service;\n\nimport org.springframework.stereotype.Service;\n\n@Service\npublic class HelloService {\n    public String getGreeting() {\n        return \"Hello from Service!\";\n    }\n}\n<\/pre>\n<h4>Repository Package<\/h4>\n<p>\nThe <code>repository<\/code> package is responsible for interacting with the database. It usually extends <code>JpaRepository<\/code> to provide CRUD functionality.\n<\/p>\n<pre>\npackage com.example.demo.repository;\n\nimport org.springframework.data.jpa.repository.JpaRepository;\nimport org.springframework.stereotype.Repository;\nimport com.example.demo.model.User;\n\n@Repository\npublic interface UserRepository extends JpaRepository<User, Long> {\n}\n<\/pre>\n<h2>2. src\/main\/resources Directory<\/h2>\n<p>\nThe <code>src\/main\/resources<\/code> directory is where static files, templates, and configuration files used by the application are located. The main files and directories in this location are as follows.\n<\/p>\n<h3>2.1 application.properties<\/h3>\n<p>\n    The configuration file <code>application.properties<\/code> is responsible for application environment settings. Here, you can set database configurations, port numbers, log levels, etc.\n<\/p>\n<pre>\nspring.datasource.url=jdbc:mysql:\/\/localhost:3306\/demo\nspring.datasource.username=root\nspring.datasource.password=password\nserver.port=8080\nlogging.level.org.springframework=DEBUG\n<\/pre>\n<h3>2.2 static Directory<\/h3>\n<p>\nThe <code>static<\/code> directory is where static resources like CSS, JavaScript, and image files are stored. Spring Boot automatically serves all files in this directory.\n<\/p>\n<h3>2.3 templates Directory<\/h3>\n<p>\nThe <code>templates<\/code> directory is used to dynamically generate HTML files using a template engine like Thymeleaf. You can create HTML files here and inject dynamic data.\n<\/p>\n<pre>\n<!DOCTYPE html>\n\n<html xmlns:th=\"http:\/\/www.thymeleaf.org\">\n<head>\n    <title>Welcome<\/title>\n<\/head>\n<body>\n    <h1 th:text=\"${message}\">Welcome Message<\/h1>\n<\/body>\n<\/html>\n<\/pre>\n<h2>3. src\/test\/java Directory<\/h2>\n<p>\nThe <code>src\/test\/java<\/code> directory contains sources related to the application&#8217;s tests. Unit tests and integration tests are performed using testing frameworks like JUnit and Mockito.\n<\/p>\n<pre>\npackage com.example.demo;\n\nimport org.junit.jupiter.api.Test;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.boot.test.context.SpringBootTest;\n\n@SpringBootTest\npublic class DemoApplicationTests {\n    \n    @Autowired\n    private HelloService helloService;\n\n    @Test\n    void contextLoads() {\n        assertNotNull(helloService);\n    }\n}\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>\n    In this course, we have explored in detail how to structure the <code>main<\/code> directory of a Spring Boot project. By understanding the project structure and configuring it correctly, developers can write more efficient and maintainable code. This structure will significantly aid in future maintenance and collaboration. Wishing you successful Spring Boot backend development.\n<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring Boot is a Java-based framework that helps developers build applications easily without complex configurations. This course will cover how to structure the main directory of a Spring Boot project. This directory serves as the starting point for a Java application and is where the important business logic is implemented. Spring Boot Project Structure A &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33003\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Spring Boot Backend Development Course, Configuring the Main Directory&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[131],"tags":[],"class_list":["post-33003","post","type-post","status-publish","format-standard","hentry","category-spring-boot-backend-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring Boot Backend Development Course, Configuring the Main Directory - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/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:\/\/atmokpo.com\/w\/33003\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Boot Backend Development Course, Configuring the Main Directory - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Spring Boot is a Java-based framework that helps developers build applications easily without complex configurations. This course will cover how to structure the main directory of a Spring Boot project. This directory serves as the starting point for a Java application and is where the important business logic is implemented. Spring Boot Project Structure A &hellip; \ub354 \ubcf4\uae30 &quot;Spring Boot Backend Development Course, Configuring the Main Directory&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33003\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:13:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:29:25+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/33003\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33003\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Spring Boot Backend Development Course, Configuring the Main Directory\",\"datePublished\":\"2024-11-01T09:13:03+00:00\",\"dateModified\":\"2024-11-01T11:29:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33003\/\"},\"wordCount\":453,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Spring Boot backend development\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33003\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33003\/\",\"name\":\"Spring Boot Backend Development Course, Configuring the Main Directory - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:13:03+00:00\",\"dateModified\":\"2024-11-01T11:29:25+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33003\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33003\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33003\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring Boot Backend Development Course, Configuring the Main Directory\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Boot Backend Development Course, Configuring the Main Directory - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","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:\/\/atmokpo.com\/w\/33003\/","og_locale":"ko_KR","og_type":"article","og_title":"Spring Boot Backend Development Course, Configuring the Main Directory - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Spring Boot is a Java-based framework that helps developers build applications easily without complex configurations. This course will cover how to structure the main directory of a Spring Boot project. This directory serves as the starting point for a Java application and is where the important business logic is implemented. Spring Boot Project Structure A &hellip; \ub354 \ubcf4\uae30 \"Spring Boot Backend Development Course, Configuring the Main Directory\"","og_url":"https:\/\/atmokpo.com\/w\/33003\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:13:03+00:00","article_modified_time":"2024-11-01T11:29:25+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/33003\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33003\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Spring Boot Backend Development Course, Configuring the Main Directory","datePublished":"2024-11-01T09:13:03+00:00","dateModified":"2024-11-01T11:29:25+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33003\/"},"wordCount":453,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Spring Boot backend development"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33003\/","url":"https:\/\/atmokpo.com\/w\/33003\/","name":"Spring Boot Backend Development Course, Configuring the Main Directory - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:13:03+00:00","dateModified":"2024-11-01T11:29:25+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33003\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33003\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33003\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Spring Boot Backend Development Course, Configuring the Main Directory"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33003","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=33003"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33003\/revisions"}],"predecessor-version":[{"id":33004,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33003\/revisions\/33004"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33003"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}