{"id":33251,"date":"2024-11-01T09:14:53","date_gmt":"2024-11-01T09:14:53","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33251"},"modified":"2024-11-01T11:28:15","modified_gmt":"2024-11-01T11:28:15","slug":"spring-boot-backend-development-course-automatic-configuration","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33251\/","title":{"rendered":"Spring Boot Backend Development Course, Automatic Configuration"},"content":{"rendered":"<p><body><\/p>\n<p>Hello! Today, we will dive into one of the most important concepts in backend development using Spring Boot: &#8216;Autoconfiguration&#8217;. Spring Boot is a tool that helps developers create applications more easily, minimizing complex setup tasks through its autoconfiguration feature. In this article, we will explore the concept of autoconfiguration, its operating principles, example code, and how it can be utilized in real applications.<\/p>\n<h2>1. What is Spring Boot?<\/h2>\n<p>Spring Boot is a framework built on top of the Spring Framework that focuses on making application development easier and minimizing configuration. Spring Boot has the following features:<\/p>\n<ul>\n<li>Autoconfiguration: Automatically finds and provides the necessary configurations, reducing the parts developers need to configure manually.<\/li>\n<li>Starter Dependencies: Provides predefined dependencies for common use cases for easy setup.<\/li>\n<li>Easy Deployment: You can run the application without separate server setup through the embedded server.<\/li>\n<\/ul>\n<h2>2. Overview of Autoconfiguration<\/h2>\n<p>Autoconfiguration is one of the core features of Spring Boot that automatically registers the necessary beans when the application starts. This feature is designed to be used only when certain conditions are met using the <strong>Conditional<\/strong> annotation. Autoconfiguration operates through configurations defined in the <em>spring.factories<\/em> file, which contains various settings for bean creation based on specific conditions.<\/p>\n<h3>2.1 Need for Autoconfiguration<\/h3>\n<p>When developing traditional Spring applications, it was necessary to manually register beans in numerous XML files or JavaConfig classes. This reduced code readability and demanded a lot of effort when changing settings. Spring Boot provides autoconfiguration technology to address these issues.<\/p>\n<h3>2.2 How Autoconfiguration Works<\/h3>\n<p>In Spring Boot, autoconfiguration works in the following way:<\/p>\n<ol>\n<li>When the application starts, Spring Boot reads the <em>spring.factories<\/em> file.<\/li>\n<li>It retrieves the list of autoconfiguration classes from the file and loads those classes.<\/li>\n<li>Each autoconfiguration class checks conditions as determined by the <strong>@Conditional<\/strong> annotation.<\/li>\n<li>If the conditions are met, it generates and registers the necessary beans through that class.<\/li>\n<\/ol>\n<h2>3. Example Configuration for Autoconfiguration<\/h2>\n<p>Now, let&#8217;s look at how to set up Spring Boot&#8217;s autoconfiguration feature through actual code.<\/p>\n<h3>3.1 Project Creation<\/h3>\n<p>To create a Spring Boot project, use <a href=\"https:\/\/start.spring.io\/\">Spring Initializr<\/a> to create a basic project and add the following dependencies:<\/p>\n<ul>\n<li>Spring Web<\/li>\n<li>Spring Data JPA<\/li>\n<li>H2 Database<\/li>\n<\/ul>\n<h3>3.2 Setting application.properties<\/h3>\n<p>Set the src\/main\/resources\/application.properties file like this:<\/p>\n<pre><code>spring.h2.console.enabled=true\nspring.datasource.url=jdbc:h2:mem:testdb\nspring.datasource.driverClassName=org.h2.Driver\nspring.datasource.username=sa\nspring.datasource.password=<\/code><\/pre>\n<h3>3.3 Creating Domain Objects and Repository<\/h3>\n<pre><code>import javax.persistence.Entity;\nimport javax.persistence.GeneratedValue;\nimport javax.persistence.GenerationType;\nimport javax.persistence.Id;\n\n@Entity\npublic class User {\n    @Id\n    @GeneratedValue(strategy = GenerationType.IDENTITY)\n    private Long id;\n    private String name;\n    private String email;\n\n    \/\/ Getters and Setters\n}<\/code><\/pre>\n<pre><code>import org.springframework.data.jpa.repository.JpaRepository;\n\npublic interface UserRepository extends JpaRepository&lt;User, Long&gt; {\n}<\/code><\/pre>\n<h3>3.4 Testing Autoconfiguration<\/h3>\n<p>Now, let&#8217;s create a simple REST API to test the autoconfigured UserRepository:<\/p>\n<pre><code>import org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.web.bind.annotation.*;\n\nimport java.util.List;\n\n@RestController\n@RequestMapping(\"\/users\")\npublic class UserController {\n    @Autowired\n    private UserRepository userRepository;\n\n    @GetMapping\n    public List&lt;User&gt; getAllUsers() {\n        return userRepository.findAll();\n    }\n\n    @PostMapping\n    public User createUser(@RequestBody User user) {\n        return userRepository.save(user);\n    }\n}<\/code><\/pre>\n<h2>4. Conditional Autoconfiguration<\/h2>\n<p>Spring Boot&#8217;s autoconfiguration can work conditionally. By using the <strong>@Conditional<\/strong> annotation, you can set it to not execute the autoconfiguration unless specific conditions are met.<\/p>\n<h3>4.1 Conditional Example<\/h3>\n<p>For example, if you only want to activate JPA-related configurations when a specific database is available, you can set it up like this:<\/p>\n<pre><code>import org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Conditional;\nimport org.springframework.context.annotation.Configuration;\n\n@Configuration\n@ConditionalOnClass(DataSource.class)\npublic class DataSourceAutoConfiguration {\n    @Bean\n    public DataSource dataSource() {\n        \/\/ Logic for creating data source bean\n    }\n}<\/code><\/pre>\n<h2>5. Customizing Autoconfiguration<\/h2>\n<p>One of the powerful features of Spring Boot is that developers can customize it beyond the default autoconfiguration as needed. There are various ways to customize the behavior of autoconfiguration:<\/p>\n<h3>5.1 Utilizing @ConfigurationProperties<\/h3>\n<p>The @ConfigurationProperties annotation allows you to inject configuration values from external configuration files (application.properties, application.yml). This makes it easy to manage specific properties of the application.<\/p>\n<h3>5.2 @ConditionalOnMissingBean Annotation<\/h3>\n<p>This annotation allows autoconfiguration only when a specific bean does not exist in the application. For example, if there is a bean defined by the user, the default bean won&#8217;t be overridden.<\/p>\n<h2>6. Conclusion<\/h2>\n<p>The autoconfiguration feature of Spring Boot helps developers save time spent on configurations in their applications, allowing them to focus more on business logic. This tutorial covered the basic concepts of autoconfiguration, example code, and customization methods comprehensively. We hope this will help you build cloud-native applications through various backend development using Spring Boot.<\/p>\n<h2>7. Additional Resources<\/h2>\n<p>For more information about Spring Boot, you can receive updates through the official documentation and community:<\/p>\n<ul>\n<li><a href=\"https:\/\/spring.io\/projects\/spring-boot\">Official Spring Boot Page<\/a><\/li>\n<li><a href=\"https:\/\/docs.spring.io\/spring-boot\/docs\/current\/reference\/htmlsingle\/\">Official Documentation<\/a><\/li>\n<li><a href=\"https:\/\/stackoverflow.com\/questions\/tagged\/spring-boot\">Spring Boot Tag on Stack Overflow<\/a><\/li>\n<\/ul>\n<p>This concludes the tutorial on Spring Boot&#8217;s autoconfiguration. If you have any questions, please leave a comment!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! Today, we will dive into one of the most important concepts in backend development using Spring Boot: &#8216;Autoconfiguration&#8217;. Spring Boot is a tool that helps developers create applications more easily, minimizing complex setup tasks through its autoconfiguration feature. In this article, we will explore the concept of autoconfiguration, its operating principles, example code, and &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33251\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Spring Boot Backend Development Course, Automatic Configuration&#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-33251","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, Automatic Configuration - \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\/33251\/\" \/>\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, Automatic Configuration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello! Today, we will dive into one of the most important concepts in backend development using Spring Boot: &#8216;Autoconfiguration&#8217;. Spring Boot is a tool that helps developers create applications more easily, minimizing complex setup tasks through its autoconfiguration feature. In this article, we will explore the concept of autoconfiguration, its operating principles, example code, and &hellip; \ub354 \ubcf4\uae30 &quot;Spring Boot Backend Development Course, Automatic Configuration&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33251\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:14:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:28:15+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=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/33251\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33251\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Spring Boot Backend Development Course, Automatic Configuration\",\"datePublished\":\"2024-11-01T09:14:53+00:00\",\"dateModified\":\"2024-11-01T11:28:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33251\/\"},\"wordCount\":648,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Spring Boot backend development\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33251\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33251\/\",\"name\":\"Spring Boot Backend Development Course, Automatic Configuration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:14:53+00:00\",\"dateModified\":\"2024-11-01T11:28:15+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33251\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33251\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33251\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring Boot Backend Development Course, Automatic Configuration\"}]},{\"@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, Automatic Configuration - \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\/33251\/","og_locale":"ko_KR","og_type":"article","og_title":"Spring Boot Backend Development Course, Automatic Configuration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello! Today, we will dive into one of the most important concepts in backend development using Spring Boot: &#8216;Autoconfiguration&#8217;. Spring Boot is a tool that helps developers create applications more easily, minimizing complex setup tasks through its autoconfiguration feature. In this article, we will explore the concept of autoconfiguration, its operating principles, example code, and &hellip; \ub354 \ubcf4\uae30 \"Spring Boot Backend Development Course, Automatic Configuration\"","og_url":"https:\/\/atmokpo.com\/w\/33251\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:14:53+00:00","article_modified_time":"2024-11-01T11:28:15+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":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/33251\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33251\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Spring Boot Backend Development Course, Automatic Configuration","datePublished":"2024-11-01T09:14:53+00:00","dateModified":"2024-11-01T11:28:15+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33251\/"},"wordCount":648,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Spring Boot backend development"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33251\/","url":"https:\/\/atmokpo.com\/w\/33251\/","name":"Spring Boot Backend Development Course, Automatic Configuration - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:14:53+00:00","dateModified":"2024-11-01T11:28:15+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33251\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33251\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33251\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Spring Boot Backend Development Course, Automatic Configuration"}]},{"@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\/33251","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=33251"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33251\/revisions"}],"predecessor-version":[{"id":33252,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33251\/revisions\/33252"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}