{"id":86820,"date":"2025-05-11T14:08:42","date_gmt":"2025-05-11T07:08:42","guid":{"rendered":"https:\/\/itviec1.uptech.vn\/?p=86820"},"modified":"2025-05-11T14:08:42","modified_gmt":"2025-05-11T07:08:42","slug":"spring-java-la-gi","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/spring-java-la-gi\/","title":{"rendered":"Spring Java l\u00e0 g\u00ec: H\u01b0\u1edbng d\u1eabn chi ti\u1ebft c\u00e1ch b\u1eaft \u0111\u1ea7u v\u1edbi Spring"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed9i dung b\u00e0i vi\u1ebft<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itviec.com\/blog\/spring-java-la-gi\/#Spring_Java_Framework_la_gi\" >Spring Java Framework l\u00e0 g\u00ec?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itviec.com\/blog\/spring-java-la-gi\/#Huong_dan_bat_dau_du_an_Spring_Java\" >H\u01b0\u1edbng d\u1eabn b\u1eaft \u0111\u1ea7u d\u1ef1 \u00e1n Spring Java<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itviec.com\/blog\/spring-java-la-gi\/#Nhung_kinh_nghiem_khi_lam_viec_voi_Spring_Java\" >Nh\u1eefng kinh nghi\u1ec7m khi l\u00e0m vi\u1ec7c v\u1edbi Spring Java<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itviec.com\/blog\/spring-java-la-gi\/#Cac_cau_hoi_thuong_gap_ve_Spring_Java\" >C\u00e1c c\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 Spring Java<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itviec.com\/blog\/spring-java-la-gi\/#Tong_ket\" >T\u1ed5ng k\u1ebft<\/a><\/li><\/ul><\/nav><\/div>\n<p><em><strong>Spring Framework n\u1ed5i l\u00ean nh\u01b0 m\u1ed9t gi\u1ea3i ph\u00e1p h\u00e0ng \u0111\u1ea7u \u0111\u1ed1i v\u1edbi c\u00e1c l\u1eadp tr\u00ecnh vi\u00ean Java \u0111ang t\u00ecm ki\u1ebfm ph\u01b0\u01a1ng ph\u00e1p \u0111\u1ec3 t\u1ed1i \u01b0u h\u00f3a v\u00e0 \u0111\u01a1n gi\u1ea3n h\u00f3a qu\u00e1 tr\u00ecnh x\u00e2y d\u1ef1ng \u1ee9ng d\u1ee5ng, b\u1ed5 sung v\u00e0 n\u00e2ng cao n\u0103ng su\u1ea5t b\u1eb1ng m\u1ed9t c\u1ea5u tr\u00fac n\u1ec1n t\u1ea3ng v\u00e0 b\u1ed9 c\u00f4ng c\u1ee5 phong ph\u00fa. Khi b\u1ea1n t\u00ecm hi\u1ec3u s\u00e2u h\u01a1n v\u1ec1 l\u1ee3i \u00edch, c\u00e1ch th\u1ee9c ho\u1ea1t \u0111\u1ed9ng c\u1ed1t l\u00f5i v\u00e0 nh\u1eefng b\u01b0\u1edbc \u0111\u1ea7u ti\u00ean \u0111\u1ec3 \u00e1p d\u1ee5ng Spring, b\u1ea1n s\u1ebd kh\u00e1m ph\u00e1 ra c\u00e1ch framework n\u00e0y gi\u00fap h\u1ee3p l\u00fd h\u00f3a quy tr\u00ecnh l\u00e0m vi\u1ec7c, gi\u00fap b\u1ea1n x\u00e2y d\u1ef1ng c\u00e1c \u1ee9ng d\u1ee5ng Java m\u1ea1nh m\u1ebd, linh ho\u1ea1t v\u00e0 d\u1ec5 b\u1ea3o tr\u00ec h\u01a1n.<\/strong><\/em><\/p>\n<p>\u0110\u1ecdc b\u00e0i vi\u1ebft n\u00e0y \u0111\u1ec3 bi\u1ebft th\u00eam chi ti\u1ebft:<\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Spring Java Framework l\u00e0 g\u00ec?<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Thi\u1ebft l\u1eadp d\u1ef1 \u00e1n Spring Java \u0111\u1ea7u ti\u00ean nh\u01b0 th\u1ebf n\u00e0o?<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Nh\u1eefng kinh nghi\u1ec7m khi l\u00e0m vi\u1ec7c v\u1edbi Spring Java\u00a0<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Spring_Java_Framework_la_gi\"><\/span><strong>Spring Java Framework l\u00e0 g\u00ec?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">V\u1ec1 b\u1ea3n ch\u1ea5t, <\/span><a href=\"https:\/\/spring.io\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Spring<\/span><\/a><span style=\"font-weight: 400;\"> l\u00e0 m\u1ed9t <\/span><b>framework \u1ee9ng d\u1ee5ng m\u00e3 ngu\u1ed3n m\u1edf to\u00e0n di\u1ec7n,<\/b><span style=\"font-weight: 400;\"> \u0111\u1ed3ng th\u1eddi c\u0169ng l\u00e0 m\u1ed9t <\/span><b>Inversion of Control (IoC) container<\/b><span style=\"font-weight: 400;\"> m\u1ea1nh m\u1ebd \u0111\u01b0\u1ee3c thi\u1ebft k\u1ebf \u0111\u1eb7c bi\u1ec7t cho n\u1ec1n t\u1ea3ng Java. Vai tr\u00f2 ch\u00ednh c\u1ee7a n\u00f3 l\u00e0 cung c\u1ea5p m\u1ed9t m\u00f4 h\u00ecnh l\u1eadp tr\u00ecnh v\u00e0 c\u1ea5u h\u00ecnh nh\u1ea5t qu\u00e1n, gi\u00fap \u0111\u01a1n gi\u1ea3n h\u00f3a vi\u1ec7c x\u00e2y d\u1ef1ng c\u00e1c \u1ee9ng d\u1ee5ng Java t\u1eeb quy m\u00f4 nh\u1ecf \u0111\u1ebfn c\u00e1c h\u1ec7 th\u1ed1ng doanh nghi\u1ec7p ph\u1ee9c t\u1ea1p.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">M\u1ee5c ti\u00eau c\u1ed1t l\u00f5i khi Spring ra \u0111\u1eddi l\u00e0 nh\u1eb1m <\/span>gi\u1ea3m thi\u1ec3u \u0111\u00e1ng k\u1ec3 s\u1ef1 ph\u1ee9c t\u1ea1p th\u01b0\u1eddng th\u1ea5y trong vi\u1ec7c ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng theo chu\u1ea9n Java EE (nay l\u00e0 Jakarta EE) tr\u01b0\u1edbc \u0111\u00e2y. \u0110\u1ec3 l\u00e0m \u0111\u01b0\u1ee3c \u0111i\u1ec1u n\u00e0y, Spring th\u00fac \u0111\u1ea9y m\u1ea1nh m\u1ebd vi\u1ec7c s\u1eed d\u1ee5ng POJOs (Plain Old Java Objects) &#8211; t\u1ee9c l\u00e0 c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng Java thu\u1ea7n t\u00fay, kh\u00f4ng b\u1ecb r\u00e0ng bu\u1ed9c ch\u1eb7t ch\u1ebd v\u00e0o framework &#8211; v\u00e0 khuy\u1ebfn kh\u00edch l\u1eadp tr\u00ecnh h\u01b0\u1edbng \u0111\u1ebfn interface (programming to interfaces). C\u00e1ch ti\u1ebfp c\u1eadn n\u00e0y gi\u00fap t\u1ea1o ra m\u00e3 ngu\u1ed3n linh ho\u1ea1t h\u01a1n, d\u1ec5 d\u00e0ng cho vi\u1ec7c ki\u1ec3m th\u1eed (testing) v\u00e0 b\u1ea3o tr\u00ec sau n\u00e0y.<\/p>\n<p>H\u01a1n n\u1eefa, Spring cung c\u1ea5p m\u1ed9t c\u1ea5u tr\u00fac \u0111\u01b0\u1ee3c module h\u00f3a cao, cho ph\u00e9p c\u00e1c nh\u00e0 ph\u00e1t tri\u1ec3n l\u1ef1a ch\u1ecdn v\u00e0 t\u00edch h\u1ee3p ch\u1ec9 nh\u1eefng th\u00e0nh ph\u1ea7n (modules) m\u00e0 h\u1ecd th\u1ef1c s\u1ef1 c\u1ea7n cho d\u1ef1 \u00e1n c\u1ee7a m\u00ecnh, t\u1ea1o n\u00ean s\u1ef1 linh ho\u1ea1t t\u1ed1i \u0111a.<\/p>\n<p><span style=\"font-weight: 400;\">D\u01b0\u1edbi \u0111\u00e2y ta c\u00f3 m\u1ed9t b\u1ea3ng so s\u00e1nh gi\u1eefa Spring v\u00e0 Java EE nh\u01b0 sau:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td><b>Ti\u00eau ch\u00ed<\/b><\/td>\n<td><b>Spring Framework\u00a0<\/b><\/td>\n<td><b>Java EE<\/b><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">B\u1ea3n ch\u1ea5t &amp; Qu\u1ea3n l\u00fd<\/span><\/td>\n<td><b>Framework &amp; H\u1ec7 sinh th\u00e1i<\/b><span style=\"font-weight: 400;\"> m\u00e3 ngu\u1ed3n m\u1edf (hi\u1ec7n thu\u1ed9c Broadcom). Cung c\u1ea5p gi\u1ea3i ph\u00e1p c\u1ee5 th\u1ec3.<\/span><\/td>\n<td><span style=\"font-weight: 400;\">B\u1ed9 <\/span><b>\u0110\u1eb7c t\u1ea3 (Specifications)<\/b><span style=\"font-weight: 400;\"> chu\u1ea9n h\u00f3a (do Eclipse Foundation qu\u1ea3n l\u00fd).<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">Runtime &amp; Deployment<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Th\u01b0\u1eddng <\/span><b>nh\u00fang server<\/b><span style=\"font-weight: 400;\"> (vd: Tomcat) \u0111\u1ec3 ch\u1ea1y \u0111\u1ed9c l\u1eadp (v\u1edbi Boot). Linh ho\u1ea1t trong tri\u1ec3n khai.<\/span><\/td>\n<td><b>Y\u00eau c\u1ea7u Application Server<\/b><span style=\"font-weight: 400;\"> t\u01b0\u01a1ng th\u00edch (vd: WildFly, GlassFish) \u0111\u1ec3 cung c\u1ea5p runtime &amp; API.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">C\u00e1ch ti\u1ebfp c\u1eadn &amp; H\u1ec7 sinh th\u00e1i<\/span><\/td>\n<td><span style=\"font-weight: 400;\">T\u1eadp trung m\u1ea1nh v\u00e0o <\/span><b>Dependency Injection (DI), AOP<\/b><span style=\"font-weight: 400;\">. H\u1ec7 sinh th\u00e1i <\/span><b>module c\u1ef1c k\u1ef3 phong ph\u00fa<\/b><span style=\"font-weight: 400;\"> (Data, Security, Cloud&#8230;).<\/span><\/td>\n<td><span style=\"font-weight: 400;\">X\u00e2y d\u1ef1ng d\u1ef1a tr\u00ean c\u00e1c <\/span><b>API &amp; Component model chu\u1ea9n<\/b><span style=\"font-weight: 400;\"> (CDI, JPA, Servlet&#8230;). H\u1ec7 sinh th\u00e1i t\u1eadp trung v\u00e0o \u0111\u1eb7c t\u1ea3.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">C\u1ea5u h\u00ecnh &amp; Linh ho\u1ea1t<\/span><\/td>\n<td><b>R\u1ea5t linh ho\u1ea1t<\/b><span style=\"font-weight: 400;\"> (XML, Annotations, Java Config). Spring Boot \u0111\u1ea9y m\u1ea1nh &#8220;Convention over Configuration&#8221;.<\/span><\/td>\n<td><b>Chu\u1ea9n h\u00f3a cao<\/b><span style=\"font-weight: 400;\"> (ch\u1ee7 y\u1ebfu Annotations, XML). \u0110\u1ea3m b\u1ea3o t\u00ednh di \u0111\u1ed9ng, c\u00f3 th\u1ec3 k\u00e9m linh ho\u1ea1t h\u01a1n trong l\u1ef1a ch\u1ecdn th\u01b0 vi\u1ec7n\/c\u1ea5u h\u00ecnh.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">\u0110i\u1ec1u c\u1ef1c k\u1ef3 quan tr\u1ecdng c\u1ea7n hi\u1ec3u r\u00f5:<\/span><\/p>\n<ul>\n<li><b>Spring kh\u00f4ng h\u1ec1 thay th\u1ebf ng\u00f4n ng\u1eef Java hay c\u00e1c API Java ti\u00eau chu\u1ea9n<\/b><span style=\"font-weight: 400;\"> nh\u01b0 Servlet API, Java Persistence API (JPA), hay Java Message Service (JMS). Thay v\u00e0o \u0111\u00f3, Spring x\u00e2y d\u1ef1ng d\u1ef1a tr\u00ean n\u1ec1n t\u1ea3ng v\u1eefng ch\u1eafc n\u00e0y.<\/span><\/li>\n<li>Spring cung c\u1ea5p c\u00e1c l\u1edbp tr\u1eebu t\u01b0\u1ee3ng h\u00f3a (abstractions) v\u00e0 v\u00f4 s\u1ed1 ti\u1ec7n \u00edch cao c\u1ea5p h\u01a1n, gi\u00fap \u0111\u01a1n gi\u1ea3n h\u00f3a vi\u1ec7c s\u1eed d\u1ee5ng c\u00e1c c\u00f4ng ngh\u1ec7 \u0111\u00f3, cho ph\u00e9p l\u1eadp tr\u00ecnh vi\u00ean t\u1eadp trung nhi\u1ec1u h\u01a1n v\u00e0o vi\u1ec7c gi\u1ea3i quy\u1ebft logic nghi\u1ec7p v\u1ee5 c\u1ed1t l\u00f5i c\u1ee7a \u1ee9ng d\u1ee5ng.<\/li>\n<\/ul>\n<blockquote><p><em>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/spring-framework\/\" target=\"_blank\" rel=\"noopener\"><strong>Spring Framework v\u00e0 h\u1ec7 sinh th\u00e1i v\u1eefng ch\u1eafc cho \u1ee9ng d\u1ee5ng Java<\/strong><\/a><\/em><\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"Huong_dan_bat_dau_du_an_Spring_Java\"><\/span><b>H\u01b0\u1edbng d\u1eabn b\u1eaft \u0111\u1ea7u d\u1ef1 \u00e1n Spring Java<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">\u0110\u1ec3 b\u1eaft \u0111\u1ea7u d\u1ef1 \u00e1n Spring Java, l\u1eadp tr\u00ecnh vi\u00ean Java c\u1ea7n bi\u1ebft v\u1ec1 <strong>Spring Boot<\/strong>. <\/span><span style=\"font-weight: 400;\">Spring Boot kh\u00f4ng thay th\u1ebf Spring Framework, m\u00e0 n\u00f3 l\u00e0 m\u1ed9t c\u00e1ch ti\u1ebfp c\u1eadn <\/span><b>&#8220;opinionated&#8221;<\/b><span style=\"font-weight: 400;\"> (c\u00f3 ch\u00ednh ki\u1ebfn, \u0111\u01b0a ra l\u1ef1a ch\u1ecdn s\u1eb5n) \u0111\u1ec3 x\u00e2y d\u1ef1ng \u1ee9ng d\u1ee5ng Spring m\u1ed9t c\u00e1ch nhanh ch\u00f3ng v\u00e0 hi\u1ec7u qu\u1ea3, \u0111\u1eb7c bi\u1ec7t ph\u00f9 h\u1ee3p cho ng\u01b0\u1eddi m\u1edbi b\u1eaft \u0111\u1ea7u v\u00e0 ph\u00e1t tri\u1ec3n microservices.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">C\u00f9ng b\u1eaft \u0111\u1ea7u\u00a0d\u1ef1 \u00e1n Spring Java theo c\u00e1c b\u01b0\u1edbc sau:<\/span><\/p>\n<h3><b>Thi\u1ebft l\u1eadp m\u00f4i tr\u01b0\u1eddng<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Tr\u01b0\u1edbc khi t\u1ea1o d\u1ef1 \u00e1n Spring Boot \u0111\u1ea7u ti\u00ean, h\u00e3y \u0111\u1ea3m b\u1ea3o b\u1ea1n \u0111\u00e3 c\u00e0i \u0111\u1eb7t c\u00e1c c\u00f4ng c\u1ee5 c\u1ea7n thi\u1ebft sau tr\u00ean m\u00e1y t\u00ednh:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Java Development Kit (JDK):<\/b><span style=\"font-weight: 400;\"> Spring Boot 3.x y\u00eau c\u1ea7u JDK 17 tr\u1edf l\u00ean. H\u00e3y ki\u1ec3m tra phi\u00ean b\u1ea3n Java c\u1ee7a b\u1ea1n b\u1eb1ng l\u1ec7nh java -version. B\u1ea1n c\u00f3 th\u1ec3 t\u1ea3i JDK t\u1eeb Oracle, OpenJDK, Adoptium, v.v.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>C\u00f4ng c\u1ee5 x\u00e2y d\u1ef1ng (Build Tool):<\/b><span style=\"font-weight: 400;\"> B\u1ea1n c\u1ea7n m\u1ed9t trong hai c\u00f4ng c\u1ee5 qu\u1ea3n l\u00fd dependency v\u00e0 x\u00e2y d\u1ef1ng d\u1ef1 \u00e1n ph\u1ed5 bi\u1ebfn l\u00e0:<\/span>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Maven:<\/b><span style=\"font-weight: 400;\"> M\u1ed9t c\u00f4ng c\u1ee5 qu\u1ea3n l\u00fd d\u1ef1 \u00e1n v\u00e0 build t\u1ef1 \u0111\u1ed9ng m\u1ea1nh m\u1ebd.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Gradle:<\/b><span style=\"font-weight: 400;\"> M\u1ed9t c\u00f4ng c\u1ee5 build t\u1ef1 \u0111\u1ed9ng kh\u00e1c, th\u01b0\u1eddng \u0111\u01b0\u1ee3c bi\u1ebft \u0111\u1ebfn v\u1edbi hi\u1ec7u su\u1ea5t t\u1ed1t v\u00e0 k\u1ecbch b\u1ea3n build linh ho\u1ea1t h\u01a1n (s\u1eed d\u1ee5ng Groovy ho\u1eb7c Kotlin DSL).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 c\u00e0i \u0111\u1eb7t Maven ho\u1eb7c Gradle ri\u00eang, ho\u1eb7c s\u1eed d\u1ee5ng phi\u00ean b\u1ea3n \u0111\u01b0\u1ee3c t\u00edch h\u1ee3p s\u1eb5n trong c\u00e1c IDE hi\u1ec7n \u0111\u1ea1i nh\u01b0 IntelliJ IDEA, Eclipse, VS Code.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3><b>T\u1ea1o d\u1ef1 \u00e1n v\u1edbi Spring Initializr<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00e1ch d\u1ec5 d\u00e0ng nh\u1ea5t \u0111\u1ec3 t\u1ea1o c\u1ea5u tr\u00fac d\u1ef1 \u00e1n Spring Boot l\u00e0 s\u1eed d\u1ee5ng <\/span><b>Spring Initializr<\/b><span style=\"font-weight: 400;\">. \u0110\u00e2y l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 web v\u00e0 c\u0169ng \u0111\u01b0\u1ee3c t\u00edch h\u1ee3p v\u00e0o h\u1ea7u h\u1ebft c\u00e1c IDE Java ph\u1ed5 bi\u1ebfn.<\/span><\/p>\n<p><b>Truy c\u1eadp:<\/b><span style=\"font-weight: 400;\"> M\u1edf tr\u00ecnh duy\u1ec7t v\u00e0 truy c\u1eadp <\/span><a href=\"https:\/\/start.spring.io\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/start.spring.io\/<\/span><\/a><\/p>\n<p><b>C\u1ea5u h\u00ecnh d\u1ef1 \u00e1n:<\/b><\/p>\n<ul>\n<li><b>Project:<\/b><span style=\"font-weight: 400;\"> Ch\u1ecdn Maven Project ho\u1eb7c Gradle Project.<\/span><\/li>\n<li><b>Language:<\/b><span style=\"font-weight: 400;\"> Ch\u1ecdn Java.<\/span><\/li>\n<li><b>Spring Boot:<\/b><span style=\"font-weight: 400;\"> Ch\u1ecdn phi\u00ean b\u1ea3n \u1ed5n \u0111\u1ecbnh m\u1edbi nh\u1ea5t (tr\u00e1nh c\u00e1c phi\u00ean b\u1ea3n SNAPSHOT ho\u1eb7c M).<\/span><\/li>\n<li><b>Project Metadata:<\/b><\/li>\n<li><b>Group:<\/b><span style=\"font-weight: 400;\"> Th\u01b0\u1eddng l\u00e0 t\u00ean mi\u1ec1n \u0111\u1ea3o ng\u01b0\u1ee3c c\u1ee7a t\u1ed5 ch\u1ee9c\/c\u00e1 nh\u00e2n (v\u00ed d\u1ee5: com.example).<\/span><\/li>\n<li><b>Artifact:<\/b><span style=\"font-weight: 400;\"> T\u00ean d\u1ef1 \u00e1n c\u1ee7a b\u1ea1n (v\u00ed d\u1ee5: my-first-app).<\/span><\/li>\n<li><b>Name:<\/b><span style=\"font-weight: 400;\"> T\u00ean d\u1ef1 \u00e1n (th\u01b0\u1eddng gi\u1ed1ng Artifact).<\/span><\/li>\n<li><b>Description:<\/b><span style=\"font-weight: 400;\"> M\u00f4 t\u1ea3 ng\u1eafn v\u1ec1 d\u1ef1 \u00e1n.<\/span><\/li>\n<li><b>Package name:<\/b><span style=\"font-weight: 400;\"> T\u00ean package g\u1ed1c (th\u01b0\u1eddng t\u1ef1 \u0111\u1ed9ng t\u1ea1o t\u1eeb Group v\u00e0 Artifact).<\/span><\/li>\n<li><b>Packaging:<\/b><span style=\"font-weight: 400;\"> Ch\u1ecdn <\/span><b>Jar<\/b><span style=\"font-weight: 400;\"> (ph\u1ed5 bi\u1ebfn nh\u1ea5t cho Spring Boot, t\u1ea1o file JAR th\u1ef1c thi).<\/span><\/li>\n<li><b>Java:<\/b><span style=\"font-weight: 400;\"> Ch\u1ecdn phi\u00ean b\u1ea3n Java b\u1ea1n \u0111\u00e3 c\u00e0i \u0111\u1eb7t (v\u00ed d\u1ee5: 17).<\/span><\/li>\n<\/ul>\n<p><b>Ch\u1ecdn Dependencies (Ph\u1ee5 thu\u1ed9c):<\/b><span style=\"font-weight: 400;\"> \u0110\u00e2y l\u00e0 b\u01b0\u1edbc quan tr\u1ecdng \u0111\u1ec3 th\u00eam c\u00e1c t\u00ednh n\u0103ng c\u1ea7n thi\u1ebft. Nh\u1ea5p v\u00e0o n\u00fat &#8220;ADD DEPENDENCIES&#8230;&#8221;. M\u1ed9t s\u1ed1 dependency ph\u1ed5 bi\u1ebfn \u0111\u1ec3 b\u1eaft \u0111\u1ea7u:<\/span><\/p>\n<ul>\n<li><b>Spring Web:<\/b><span style=\"font-weight: 400;\"> C\u1ea7n thi\u1ebft \u0111\u1ec3 x\u00e2y d\u1ef1ng \u1ee9ng d\u1ee5ng web v\u00e0 RESTful API (bao g\u1ed3m Tomcat nh\u00fang).<\/span><\/li>\n<li><b>Spring Data JPA:<\/b><span style=\"font-weight: 400;\"> (T\u00f9y ch\u1ecdn) N\u1ebfu b\u1ea1n mu\u1ed1n l\u00e0m vi\u1ec7c v\u1edbi c\u01a1 s\u1edf d\u1eef li\u1ec7u quan h\u1ec7 th\u00f4ng qua Java Persistence API.<\/span><\/li>\n<li><b>H2 Database \/ MySQL Driver \/ PostgreSQL Driver:<\/b><span style=\"font-weight: 400;\"> (T\u00f9y ch\u1ecdn) N\u1ebfu d\u00f9ng Spring Data JPA, b\u1ea1n c\u1ea7n th\u00eam driver cho c\u01a1 s\u1edf d\u1eef li\u1ec7u t\u01b0\u01a1ng \u1ee9ng (H2 l\u00e0 CSDL trong b\u1ed9 nh\u1edb, t\u1ed1t cho th\u1eed nghi\u1ec7m).<\/span><\/li>\n<li><b>Lombok:<\/b><span style=\"font-weight: 400;\"> (R\u1ea5t khuy\u1ebfn kh\u00edch) Gi\u00fap gi\u1ea3m thi\u1ec3u code so\u1ea1n s\u1eb5n trong c\u00e1c l\u1edbp Java (t\u1ef1 \u0111\u1ed9ng t\u1ea1o getters, setters, constructors&#8230;).<\/span><\/li>\n<\/ul>\n<p><b>Generate:<\/b><span style=\"font-weight: 400;\"> Nh\u1ea5p v\u00e0o n\u00fat &#8220;GENERATE&#8221;. M\u1ed9t file ZIP ch\u1ee9a c\u1ea5u tr\u00fac d\u1ef1 \u00e1n s\u1ebd \u0111\u01b0\u1ee3c t\u1ea3i v\u1ec1.<\/span><\/p>\n<p><b>M\u1edf d\u1ef1 \u00e1n:<\/b><span style=\"font-weight: 400;\"> Gi\u1ea3i n\u00e9n file ZIP v\u00e0 m\u1edf th\u01b0 m\u1ee5c d\u1ef1 \u00e1n b\u1eb1ng IDE y\u00eau th\u00edch c\u1ee7a b\u1ea1n (IntelliJ IDEA, Eclipse, VS Code). IDE s\u1ebd t\u1ef1 \u0111\u1ed9ng nh\u1eadn di\u1ec7n v\u00e0 t\u1ea3i c\u00e1c dependency \u0111\u00e3 khai b\u00e1o (th\u00f4ng qua Maven ho\u1eb7c Gradle).<\/span><\/p>\n<h3><b>C\u1ea5u tr\u00fac d\u1ef1 \u00e1n Spring Boot \u0111i\u1ec3n h\u00ecnh<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Sau khi m\u1edf d\u1ef1 \u00e1n trong IDE, b\u1ea1n s\u1ebd th\u1ea5y c\u1ea5u tr\u00fac th\u01b0 m\u1ee5c c\u01a1 b\u1ea3n nh\u01b0 sau (v\u00ed d\u1ee5 v\u1edbi Maven):<\/span><\/p>\n<p><span style=\"font-weight: 400;\">my-first-app\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u251c\u2500\u2500 .mvn\/\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\"># Maven wrapper files<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u251c\u2500\u2500 src\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u251c\u2500\u2500 main\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u2502 \u00a0 \u251c\u2500\u2500 java\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u2502 \u00a0 \u2502 \u00a0 \u2514\u2500\u2500 com\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u2502 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 example\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u2502 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 myfirstapp\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u2502 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 MyFirstAppApplication.java\u00a0 <\/span> <span style=\"font-weight: 400;\"># L\u1edbp ch\u00ednh kh\u1edfi ch\u1ea1y<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u2502 \u00a0 \u2514\u2500\u2500 resources\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u251c\u2500\u2500 application.properties\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\"># File c\u1ea5u h\u00ecnh ch\u00ednh<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u251c\u2500\u2500 static\/ \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\"># Ch\u1ee9a file t\u0129nh (CSS, JS, images)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u2502 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 templates\/ \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\"> # Ch\u1ee9a template engine files (Thymeleaf, etc.)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u2514\u2500\u2500 test\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 java\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 com\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 example\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 myfirstapp\/<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2502 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u2514\u2500\u2500 MyFirstAppApplicationTests.java <\/span> <span style=\"font-weight: 400;\"># L\u1edbp test c\u01a1 b\u1ea3n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u251c\u2500\u2500 mvnw\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\"> # Maven wrapper script (Linux\/Mac)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u251c\u2500\u2500 mvnw.cmd \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\"># Maven wrapper script (Windows)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u2514\u2500\u2500 pom.xml\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span> <span style=\"font-weight: 400;\"># File c\u1ea5u h\u00ecnh Maven (khai b\u00e1o dependency&#8230;)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>MyFirstAppApplication.java<\/b><span style=\"font-weight: 400;\">: L\u1edbp ch\u1ee9a ph\u01b0\u01a1ng th\u1ee9c main, \u0111\u01b0\u1ee3c \u0111\u00e1nh d\u1ea5u b\u1edfi @SpringBootApplication. \u0110\u00e2y l\u00e0 \u0111i\u1ec3m kh\u1edfi \u0111\u1ea7u c\u1ee7a \u1ee9ng d\u1ee5ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>src\/main\/resources<\/b><span style=\"font-weight: 400;\">: Th\u01b0 m\u1ee5c ch\u1ee9a c\u00e1c t\u00e0i nguy\u00ean kh\u00f4ng ph\u1ea3i code Java.<\/span>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>application.properties<\/b><span style=\"font-weight: 400;\"> (ho\u1eb7c application.yml): N\u01a1i b\u1ea1n \u0111\u1ecbnh ngh\u0129a c\u00e1c c\u1ea5u h\u00ecnh cho \u1ee9ng d\u1ee5ng (v\u00ed d\u1ee5: c\u1ed5ng server, th\u00f4ng tin k\u1ebft n\u1ed1i CSDL&#8230;).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>static<\/b><span style=\"font-weight: 400;\">: Ch\u1ee9a c\u00e1c t\u00e0i nguy\u00ean web t\u0129nh.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>templates<\/b><span style=\"font-weight: 400;\">: Ch\u1ee9a c\u00e1c file template n\u1ebfu b\u1ea1n s\u1eed d\u1ee5ng template engine nh\u01b0 Thymeleaf.<\/span><\/li>\n<\/ul>\n<\/li>\n<li><b>src\/test\/java<\/b><span style=\"font-weight: 400;\">: Ch\u1ee9a code ki\u1ec3m th\u1eed (unit tests, integration tests).<\/span><\/li>\n<li><b>pom.xml<\/b><span style=\"font-weight: 400;\"> (ho\u1eb7c build.gradle): File c\u1ea5u h\u00ecnh c\u1ee7a Maven (ho\u1eb7c Gradle), n\u01a1i khai b\u00e1o c\u00e1c dependency v\u00e0 c\u00e1ch build d\u1ef1 \u00e1n.<\/span><\/li>\n<\/ul>\n<h3><b>V\u00ed d\u1ee5 \u0111\u01a1n gi\u1ea3n: X\u00e2y d\u1ef1ng REST API &#8220;Hello World&#8221;<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">H\u00e3y t\u1ea1o m\u1ed9t API \u0111\u01a1n gi\u1ea3n tr\u1ea3 v\u1ec1 chu\u1ed7i &#8220;Message: Hello World!!&#8221;.<\/span><\/p>\n<p><b>T\u1ea1o Controller:<\/b><span style=\"font-weight: 400;\"> Trong package g\u1ed1c (com.example.myfirstapp), t\u1ea1o m\u1ed9t package m\u1edbi t\u00ean l\u00e0 controller. B\u00ean trong package controller, t\u1ea1o m\u1ed9t l\u1edbp Java t\u00ean l\u00e0 HelloController.java.<\/span><\/p>\n<p><b>Vi\u1ebft code Controller:<\/b><\/p>\n<pre><span style=\"font-weight: 400;\">package com.example.myfirstapp.controller;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">import org.springframework.web.bind.annotation.GetMapping;<\/span>\r\n<span style=\"font-weight: 400;\">import org.springframework.web.bind.annotation.RestController;<\/span>\r\n\r\n<span style=\"font-weight: 400;\">@RestController \/\/ \u0110\u00e1nh d\u1ea5u l\u1edbp n\u00e0y l\u00e0 m\u1ed9t REST Controller, k\u1ebft h\u1ee3p @Controller v\u00e0 @ResponseBody<\/span>\r\n<span style=\"font-weight: 400;\">public class HelloController {<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 @GetMapping(\"\/hello\") \/\/ \u00c1nh x\u1ea1 c\u00e1c HTTP GET request t\u1edbi \u0111\u01b0\u1eddng d\u1eabn \"\/hello\" v\u00e0o ph\u01b0\u01a1ng th\u1ee9c n\u00e0y<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 public String sayHello() {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 return \"Message: Hello World!!\";<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">}<\/span><\/pre>\n<p><b>@RestController<\/b><span style=\"font-weight: 400;\">: L\u00e0 m\u1ed9t annotation ti\u1ec7n l\u1ee3i, k\u1ebft h\u1ee3p <\/span><span style=\"font-weight: 400;\">@Controller<\/span><span style=\"font-weight: 400;\"> (\u0111\u00e1nh d\u1ea5u l\u1edbp l\u00e0 m\u1ed9t Spring MVC controller) v\u00e0 <\/span><span style=\"font-weight: 400;\">@ResponseBody<\/span><span style=\"font-weight: 400;\"> (ch\u1ec9 \u0111\u1ecbnh r\u1eb1ng gi\u00e1 tr\u1ecb tr\u1ea3 v\u1ec1 c\u1ee7a ph\u01b0\u01a1ng th\u1ee9c n\u00ean \u0111\u01b0\u1ee3c ghi tr\u1ef1c ti\u1ebfp v\u00e0o response body, thay v\u00ec t\u00ecm ki\u1ebfm m\u1ed9t view template).<\/span><\/p>\n<p><b>@GetMapping(&#8220;\/hello&#8221;)<\/b><span style=\"font-weight: 400;\">: \u00c1nh x\u1ea1 c\u00e1c HTTP GET request \u0111\u1ebfn \u0111\u01b0\u1eddng d\u1eabn \/hello t\u1edbi ph\u01b0\u01a1ng th\u1ee9c sayHello().<\/span><\/p>\n<h3><b>Ch\u1ea1y \u1ee9ng d\u1ee5ng<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">C\u00f3 nhi\u1ec1u c\u00e1ch \u0111\u1ec3 ch\u1ea1y \u1ee9ng d\u1ee5ng Spring Boot:<\/span><\/p>\n<h4><b>1. T\u1eeb IDE<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">H\u1ea7u h\u1ebft c\u00e1c IDE s\u1ebd nh\u1eadn di\u1ec7n l\u1edbp <\/span><b>MyFirstAppApplication.java<\/b><span style=\"font-weight: 400;\"> c\u00f3 ph\u01b0\u01a1ng th\u1ee9c main v\u00e0 annotation @SpringBootApplication. B\u1ea1n ch\u1ec9 c\u1ea7n nh\u1ea5p chu\u1ed9t ph\u1ea3i v\u00e0o l\u1edbp n\u00e0y v\u00e0 ch\u1ecdn &#8220;Run&#8221; ho\u1eb7c &#8220;Debug&#8221;. IDE s\u1ebd kh\u1edfi \u0111\u1ed9ng m\u00e1y ch\u1ee7 web nh\u00fang (Tomcat m\u1eb7c \u0111\u1ecbnh) v\u00e0 tri\u1ec3n khai \u1ee9ng d\u1ee5ng.<\/span><\/p>\n<h4><b>2. S\u1eed d\u1ee5ng Maven\/Gradle Wrapper<\/b><\/h4>\n<ul>\n<li><span style=\"font-weight: 400;\">M\u1edf terminal ho\u1eb7c command prompt trong th\u01b0 m\u1ee5c g\u1ed1c c\u1ee7a d\u1ef1 \u00e1n.<\/span><\/li>\n<li><b>Maven:<\/b><span style=\"font-weight: 400;\"> Ch\u1ea1y l\u1ec7nh <\/span><span style=\"font-weight: 400;\">.\/mvnw spring-boot:run<\/span><span style=\"font-weight: 400;\"> (Linux\/Mac) ho\u1eb7c <\/span><span style=\"font-weight: 400;\">mvnw spring-boot:run<\/span><span style=\"font-weight: 400;\"> (Windows).<\/span><\/li>\n<li><b>Gradle:<\/b><span style=\"font-weight: 400;\"> Ch\u1ea1y l\u1ec7nh<\/span><span style=\"font-weight: 400;\"> .\/gradlew bootRun (Linux\/Mac) ho\u1eb7c gradlew bootRun (Windows).<\/span><\/li>\n<\/ul>\n<h4><b>3. \u0110\u00f3ng g\u00f3i th\u00e0nh file JAR v\u00e0 ch\u1ea1y<\/b><\/h4>\n<p><strong>\u0110\u00f3ng g\u00f3i:<\/strong><\/p>\n<ul>\n<li><b>Maven:<\/b> .\/mvnw package ho\u1eb7c mvnw package<\/li>\n<li>Gradle: .\/gradlew build ho\u1eb7c gradlew build. L\u1ec7nh n\u00e0y s\u1ebd t\u1ea1o m\u1ed9t file JAR th\u1ef1c thi trong th\u01b0 m\u1ee5c target (Maven) ho\u1eb7c build\/libs (Gradle). File JAR n\u00e0y ch\u1ee9a t\u1ea5t c\u1ea3 c\u00e1c dependency v\u00e0 m\u00e1y ch\u1ee7 nh\u00fang.<\/li>\n<\/ul>\n<p><b>Ch\u1ea1y file JAR:<\/b><\/p>\n<p><span style=\"font-weight: 400;\">M\u1edf terminal, \u0111i\u1ec1u h\u01b0\u1edbng \u0111\u1ebfn th\u01b0 m\u1ee5c ch\u1ee9a file JAR v\u00e0 ch\u1ea1y l\u1ec7nh: j<\/span><span style=\"font-weight: 400;\">ava -jar ten-file-cua-ban.jar (thay ten-file-cua-ban.jar b\u1eb1ng t\u00ean file JAR th\u1ef1c t\u1ebf)<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p>Sau khi \u1ee9ng d\u1ee5ng kh\u1edfi \u0111\u1ed9ng th\u00e0nh c\u00f4ng (b\u1ea1n s\u1ebd th\u1ea5y log trong console, th\u01b0\u1eddng b\u00e1o Tomcat \u0111\u00e3 kh\u1edfi \u0111\u1ed9ng tr\u00ean c\u1ed5ng 8080), h\u00e3y m\u1edf tr\u00ecnh duy\u1ec7t web v\u00e0 truy c\u1eadp \u0111\u1ecba ch\u1ec9: http:\/\/localhost:8080\/hello<\/p>\n<p>B\u1ea1n s\u1ebd th\u1ea5y d\u00f2ng ch\u1eef &#8220;Message: Hello World!!&#8221; hi\u1ec3n th\u1ecb tr\u00ean tr\u00ecnh duy\u1ec7t.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-86821\" src=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/spring-java-1-vippro.png\" alt=\"\" width=\"986\" height=\"482\" srcset=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/spring-java-1-vippro.png 986w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/spring-java-1-vippro-300x147.png 300w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/spring-java-1-vippro-768x375.png 640w, https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/spring-java-1-vippro-200x98.png 200w\" sizes=\"auto, (max-width: 986px) 100vw, 986px\" \/><\/p>\n<p><span style=\"font-weight: 400;\">B\u1ea1n \u0111\u00e3 t\u1ea1o v\u00e0 ch\u1ea1y th\u00e0nh c\u00f4ng \u1ee9ng d\u1ee5ng Spring Boot \u0111\u1ea7u ti\u00ean c\u1ee7a m\u00ecnh. T\u1eeb \u0111\u00e2y, b\u1ea1n c\u00f3 th\u1ec3 b\u1eaft \u0111\u1ea7u kh\u00e1m ph\u00e1 c\u00e1c t\u00ednh n\u0103ng m\u1ea1nh m\u1ebd kh\u00e1c c\u1ee7a Spring Boot v\u00e0 h\u1ec7 sinh th\u00e1i Spring.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Ngo\u00e0i ra b\u1ea1n c\u00f3 th\u1ec3 truy c\u1eadp c\u00e1c source m\u1eabu c\u1ee7a Spring Boot t\u1ea1i \u0111\u00e2y: <\/span><a href=\"https:\/\/github.com\/spring-projects\/spring-boot\/tree\/main\/spring-boot-project\/spring-boot-starters\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/github.com\/spring-projects\/spring-boot\/tree\/main\/spring-boot-project\/spring-boot-starters<\/span><\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Nhung_kinh_nghiem_khi_lam_viec_voi_Spring_Java\"><\/span><b>Nh\u1eefng kinh nghi\u1ec7m khi l\u00e0m vi\u1ec7c v\u1edbi Spring Java<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Spring Framework, \u0111\u1eb7c bi\u1ec7t l\u00e0 khi k\u1ebft h\u1ee3p v\u1edbi Spring Boot, mang l\u1ea1i s\u1ee9c m\u1ea1nh v\u00e0 s\u1ef1 linh ho\u1ea1t \u0111\u00e1ng kinh ng\u1ea1c cho vi\u1ec7c ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng Java. Tuy nhi\u00ean, \u0111\u1ec3 t\u1eadn d\u1ee5ng t\u1ed1i \u0111a hi\u1ec7u qu\u1ea3 c\u1ee7a n\u00f3 v\u00e0 tr\u00e1nh nh\u1eefng c\u1ea1m b\u1eaby ph\u1ed5 bi\u1ebfn, vi\u1ec7c t\u00edch l\u0169y kinh nghi\u1ec7m th\u1ef1c t\u1ebf l\u00e0 v\u00f4 c\u00f9ng quan tr\u1ecdng. D\u01b0\u1edbi \u0111\u00e2y l\u00e0 m\u1ed9t s\u1ed1 kinh nghi\u1ec7m \u0111\u01b0\u1ee3c \u0111\u00fac k\u1ebft c\u00f3 th\u1ec3 gi\u00fap b\u1ea1n l\u00e0m vi\u1ec7c hi\u1ec7u qu\u1ea3 h\u01a1n v\u1edbi h\u1ec7 sinh th\u00e1i Spring:<\/span><\/p>\n<h3><b>N\u1eafm v\u1eefng c\u00e1c kh\u00e1i ni\u1ec7m c\u1ed1t l\u00f5i (IoC\/DI, AOP)<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Hi\u1ec3u s\u00e2u v\u1ec1 IoC\/DI:<\/b><span style=\"font-weight: 400;\"> \u0110\u1eebng ch\u1ec9 d\u1eebng l\u1ea1i \u1edf vi\u1ec7c bi\u1ebft d\u00f9ng <\/span><span style=\"font-weight: 400;\">@Autowired<\/span><span style=\"font-weight: 400;\">. H\u00e3y hi\u1ec3u c\u00e1ch IoC container ho\u1ea1t \u0111\u1ed9ng, v\u00f2ng \u0111\u1eddi c\u1ee7a bean (bean lifecycle), c\u00e1c scope kh\u00e1c nhau (singleton, prototype, request, session&#8230;), v\u00e0 c\u00e1c c\u00e1ch inject dependency (constructor, setter, field &#8211; \u01b0u ti\u00ean constructor injection v\u00ec t\u00ednh b\u1ea5t bi\u1ebfn v\u00e0 r\u00f5 r\u00e0ng). Hi\u1ec3u r\u00f5 \u0111i\u1ec1u n\u00e0y gi\u00fap b\u1ea1n tr\u00e1nh c\u00e1c l\u1ed7i li\u00ean quan \u0111\u1ebfn dependency v\u00e0 thi\u1ebft k\u1ebf \u1ee9ng d\u1ee5ng t\u1ed1t h\u01a1n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>T\u1eadn d\u1ee5ng AOP m\u1ed9t c\u00e1ch kh\u00f4n ngoan:<\/b><span style=\"font-weight: 400;\"> Aspect-Oriented Programming r\u1ea5t m\u1ea1nh m\u1ebd \u0111\u1ec3 t\u00e1ch bi\u1ec7t c\u00e1c m\u1ed1i quan t\u00e2m chung (logging, transaction, security). Tuy nhi\u00ean, l\u1ea1m d\u1ee5ng AOP c\u00f3 th\u1ec3 khi\u1ebfn lu\u1ed3ng th\u1ef1c thi tr\u1edf n\u00ean kh\u00f3 theo d\u00f5i v\u00e0 debug. H\u00e3y s\u1eed d\u1ee5ng AOP cho nh\u1eefng m\u1ee5c \u0111\u00edch r\u00f5 r\u00e0ng v\u00e0 gi\u1eef cho c\u00e1c aspect \u0111\u01a1n gi\u1ea3n, t\u1eadp trung. Lu\u00f4n c\u00e2n nh\u1eafc gi\u1eefa l\u1ee3i \u00edch c\u1ee7a vi\u1ec7c t\u00e1ch bi\u1ec7t v\u00e0 s\u1ef1 ph\u1ee9c t\u1ea1p c\u00f3 th\u1ec3 ph\u00e1t sinh.<\/span><\/li>\n<\/ul>\n<h3><b>Khai th\u00e1c t\u1ed1i \u0111a s\u1ee9c m\u1ea1nh c\u1ee7a Spring Boot<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Hi\u1ec3u Auto-configuration:<\/b><span style=\"font-weight: 400;\"> \u0110\u1eebng coi Spring Boot l\u00e0 &#8220;ma thu\u1eadt&#8221;. H\u00e3y t\u00ecm hi\u1ec3u c\u00e1ch auto-configuration ho\u1ea1t \u0111\u1ed9ng. Bi\u1ebft c\u00e1ch xem b\u00e1o c\u00e1o auto-configuration (<\/span><span style=\"font-weight: 400;\">&#8211;debug<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">management.endpoint.conditions.enabled=true<\/span><span style=\"font-weight: 400;\">) \u0111\u1ec3 hi\u1ec3u t\u1ea1i sao m\u1ed9t bean \u0111\u01b0\u1ee3c t\u1ea1o ho\u1eb7c kh\u00f4ng. \u0110i\u1ec1u n\u00e0y gi\u00fap b\u1ea1n t\u00f9y ch\u1ec9nh c\u1ea5u h\u00ecnh khi c\u1ea7n thi\u1ebft v\u00e0 gi\u1ea3i quy\u1ebft c\u00e1c v\u1ea5n \u0111\u1ec1 xung \u0111\u1ed9t c\u1ea5u h\u00ecnh.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>S\u1eed d\u1ee5ng Starters hi\u1ec7u qu\u1ea3:<\/b><span style=\"font-weight: 400;\"> Lu\u00f4n b\u1eaft \u0111\u1ea7u v\u1edbi c\u00e1c <\/span><span style=\"font-weight: 400;\">spring-boot-starter-*<\/span><span style=\"font-weight: 400;\"> ph\u00f9 h\u1ee3p. Ch\u00fang gi\u00fap qu\u1ea3n l\u00fd c\u00e1c dependency t\u01b0\u01a1ng th\u00edch m\u1ed9t c\u00e1ch d\u1ec5 d\u00e0ng. Tr\u00e1nh vi\u1ec7c th\u00eam c\u00e1c th\u01b0 vi\u1ec7n ri\u00eang l\u1ebb n\u1ebfu \u0111\u00e3 c\u00f3 starter t\u01b0\u01a1ng \u1ee9ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>T\u1eadn d\u1ee5ng Profiles:<\/b><span style=\"font-weight: 400;\"> S\u1eed d\u1ee5ng Spring Profiles (<\/span><span style=\"font-weight: 400;\">application-{profile}.properties<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">.yml<\/span><span style=\"font-weight: 400;\">) \u0111\u1ec3 qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh cho c\u00e1c m\u00f4i tr\u01b0\u1eddng kh\u00e1c nhau (dev, test, staging, prod). \u0110i\u1ec1u n\u00e0y gi\u00fap gi\u1eef c\u1ea5u h\u00ecnh s\u1ea1ch s\u1ebd v\u00e0 d\u1ec5 d\u00e0ng chuy\u1ec3n \u0111\u1ed5i gi\u1eefa c\u00e1c m\u00f4i tr\u01b0\u1eddng.<\/span><\/li>\n<\/ul>\n<h3><b>Qu\u1ea3n l\u00fd Dependencies th\u00f4ng minh<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>D\u00f9ng BOM (Bill of Materials):<\/b><span style=\"font-weight: 400;\"> Khi l\u00e0m vi\u1ec7c v\u1edbi nhi\u1ec1u module Spring (Cloud, Data, Security&#8230;), h\u00e3y s\u1eed d\u1ee5ng Spring Boot BOM ho\u1eb7c Spring Cloud BOM \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o c\u00e1c phi\u00ean b\u1ea3n th\u01b0 vi\u1ec7n t\u01b0\u01a1ng th\u00edch v\u1edbi nhau, tr\u00e1nh &#8220;dependency hell&#8221;.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ki\u1ec3m tra v\u00e0 lo\u1ea1i b\u1ecf dependency th\u1eeba:<\/b><span style=\"font-weight: 400;\"> \u0110\u1ecbnh k\u1ef3 r\u00e0 so\u00e1t <\/span><span style=\"font-weight: 400;\">pom.xml<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">build.gradle<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 lo\u1ea1i b\u1ecf c\u00e1c dependency kh\u00f4ng c\u00f2n s\u1eed d\u1ee5ng. S\u1eed d\u1ee5ng c\u00e1c plugin nh\u01b0 <\/span><span style=\"font-weight: 400;\">mvn dependency:tree<\/span><span style=\"font-weight: 400;\"> ho\u1eb7c <\/span><span style=\"font-weight: 400;\">gradle dependencies<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 ph\u00e2n t\u00edch c\u00e2y ph\u1ee5 thu\u1ed9c v\u00e0 ph\u00e1t hi\u1ec7n c\u00e1c xung \u0111\u1ed9t phi\u00ean b\u1ea3n ti\u1ec1m \u1ea9n.<\/span><\/li>\n<\/ul>\n<h3><b>Qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh linh ho\u1ea1t<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>\u01afu ti\u00ean <\/b><span style=\"font-weight: 400;\">application.yml<\/span><b>:<\/b><span style=\"font-weight: 400;\"> YAML th\u01b0\u1eddng d\u1ec5 \u0111\u1ecdc v\u00e0 c\u1ea5u tr\u00fac h\u01a1n so v\u1edbi <\/span><span style=\"font-weight: 400;\">.properties<\/span><span style=\"font-weight: 400;\">, \u0111\u1eb7c bi\u1ec7t v\u1edbi c\u00e1c c\u1ea5u h\u00ecnh ph\u1ee9c t\u1ea1p, ph\u00e2n c\u1ea5p.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Externalize Configuration:<\/b><span style=\"font-weight: 400;\"> \u0110\u1eebng hardcode c\u1ea5u h\u00ecnh trong code. S\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">application.properties<\/span><span style=\"font-weight: 400;\">\/<\/span><span style=\"font-weight: 400;\">yml<\/span><span style=\"font-weight: 400;\">, bi\u1ebfn m\u00f4i tr\u01b0\u1eddng (environment variables), ho\u1eb7c c\u00e1c h\u1ec7 th\u1ed1ng qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh t\u1eadp trung (nh\u01b0 Spring Cloud Config Server, HashiCorp Consul) \u0111\u1ec3 \u1ee9ng d\u1ee5ng linh ho\u1ea1t h\u01a1n v\u00e0 d\u1ec5 d\u00e0ng qu\u1ea3n l\u00fd trong c\u00e1c m\u00f4i tr\u01b0\u1eddng kh\u00e1c nhau.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>S\u1eed d\u1ee5ng <\/b><span style=\"font-weight: 400;\">@ConfigurationProperties<\/span><b>:<\/b><span style=\"font-weight: 400;\"> \u0110\u00e2y l\u00e0 c\u00e1ch m\u1ea1nh m\u1ebd v\u00e0 type-safe \u0111\u1ec3 li\u00ean k\u1ebft c\u00e1c thu\u1ed9c t\u00ednh c\u1ea5u h\u00ecnh v\u1edbi c\u00e1c \u0111\u1ed1i t\u01b0\u1ee3ng Java POJO, gi\u00fap code s\u1ea1ch s\u1ebd v\u00e0 d\u1ec5 refactor h\u01a1n so v\u1edbi vi\u1ec7c d\u00f9ng <\/span><span style=\"font-weight: 400;\">@Value<\/span><span style=\"font-weight: 400;\"> cho nhi\u1ec1u thu\u1ed9c t\u00ednh.<\/span><\/li>\n<\/ul>\n<h3><b>X\u00e2y d\u1ef1ng chi\u1ebfn l\u01b0\u1ee3c Testing hi\u1ec7u qu\u1ea3<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>K\u1ebft h\u1ee3p Unit Test v\u00e0 Integration Test:<\/b>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Unit Test:<\/b><span style=\"font-weight: 400;\"> T\u1eadp trung ki\u1ec3m th\u1eed logic c\u1ee7a t\u1eebng class\/component m\u1ed9t c\u00e1ch c\u00f4 l\u1eadp (s\u1eed d\u1ee5ng Mockito \u0111\u1ec3 mock dependencies). Spring Boot cung c\u1ea5p <\/span><span style=\"font-weight: 400;\">@MockBean<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 d\u1ec5 d\u00e0ng t\u00edch h\u1ee3p mock v\u00e0o context test.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><b>Integration Test:<\/b><span style=\"font-weight: 400;\"> Ki\u1ec3m th\u1eed s\u1ef1 t\u01b0\u01a1ng t\u00e1c gi\u1eefa c\u00e1c component ho\u1eb7c v\u1edbi c\u00e1c h\u1ec7 th\u1ed1ng b\u00ean ngo\u00e0i (database, API kh\u00e1c). S\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">@SpringBootTest<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 t\u1ea3i ApplicationContext v\u00e0 th\u1ef1c hi\u1ec7n ki\u1ec3m th\u1eed t\u00edch h\u1ee3p. D\u00f9ng <\/span><span style=\"font-weight: 400;\">@DataJpaTest<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">@WebMvcTest<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">@RestClientTest<\/span><span style=\"font-weight: 400;\">&#8230; cho c\u00e1c slice test c\u1ee5 th\u1ec3, gi\u00fap test nhanh h\u01a1n.<\/span><\/li>\n<\/ul>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>S\u1eed d\u1ee5ng Testcontainers:<\/b><span style=\"font-weight: 400;\"> Cho c\u00e1c integration test c\u1ea7n t\u01b0\u01a1ng t\u00e1c v\u1edbi database, message queue, ho\u1eb7c c\u00e1c d\u1ecbch v\u1ee5 kh\u00e1c, Testcontainers l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 tuy\u1ec7t v\u1eddi \u0111\u1ec3 kh\u1edfi t\u1ea1o c\u00e1c container Docker d\u00f9ng m\u1ed9t l\u1ea7n ngay trong qu\u00e1 tr\u00ecnh test, \u0111\u1ea3m b\u1ea3o m\u00f4i tr\u01b0\u1eddng test \u0111\u1ed9c l\u1eadp v\u00e0 nh\u1ea5t qu\u00e1n.<\/span><\/li>\n<\/ul>\n<h3><b>X\u1eed l\u00fd Exception nh\u1ea5t qu\u00e1n<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>S\u1eed d\u1ee5ng <\/b><span style=\"font-weight: 400;\">@ControllerAdvice<\/span><b> v\u00e0 <\/b><span style=\"font-weight: 400;\">@ExceptionHandler<\/span><b>:<\/b><span style=\"font-weight: 400;\"> T\u1ea1o m\u1ed9t c\u01a1 ch\u1ebf x\u1eed l\u00fd exception t\u1eadp trung cho c\u00e1c controller b\u1eb1ng <\/span><span style=\"font-weight: 400;\">@ControllerAdvice<\/span><span style=\"font-weight: 400;\">. \u0110\u1ecbnh ngh\u0129a c\u00e1c ph\u01b0\u01a1ng th\u1ee9c <\/span><span style=\"font-weight: 400;\">@ExceptionHandler<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 x\u1eed l\u00fd c\u00e1c lo\u1ea1i exception c\u1ee5 th\u1ec3 v\u00e0 tr\u1ea3 v\u1ec1 response l\u1ed7i chu\u1ea9n h\u00f3a cho client. Tr\u00e1nh \u0111\u1ec3 l\u1ed9 stack trace ho\u1eb7c th\u00f4ng tin nh\u1ea1y c\u1ea3m.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>\u0110\u1ecbnh ngh\u0129a c\u00e1c Custom Exception:<\/b><span style=\"font-weight: 400;\"> T\u1ea1o c\u00e1c l\u1edbp exception t\u00f9y ch\u1ec9nh (custom exception) c\u00f3 \u00fd ngh\u0129a nghi\u1ec7p v\u1ee5 r\u00f5 r\u00e0ng thay v\u00ec ch\u1ec9 d\u1ef1a v\u00e0o c\u00e1c exception chung chung c\u1ee7a Java.<\/span><\/li>\n<\/ul>\n<h3><b>L\u00e0m vi\u1ec7c hi\u1ec7u qu\u1ea3 v\u1edbi Database (Spring Data)<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Hi\u1ec3u r\u00f5 v\u1ec1 Transaction Management (<\/b><span style=\"font-weight: 400;\">@Transactional<\/span><b>):<\/b><span style=\"font-weight: 400;\"> N\u1eafm v\u1eefng c\u00e1ch <\/span><span style=\"font-weight: 400;\">@Transactional<\/span><span style=\"font-weight: 400;\"> ho\u1ea1t \u0111\u1ed9ng, c\u00e1c thu\u1ed9c t\u00ednh propagation, isolation, rollback rules. \u0110\u1eb7t <\/span><span style=\"font-weight: 400;\">@Transactional<\/span><span style=\"font-weight: 400;\"> \u1edf l\u1edbp Service thay v\u00ec l\u1edbp Repository (tr\u1eeb khi c\u00f3 l\u00fd do \u0111\u1eb7c bi\u1ec7t). C\u1ea9n th\u1eadn v\u1edbi c\u00e1c v\u1ea5n \u0111\u1ec1 v\u1ec1 proxy khi g\u1ecdi ph\u01b0\u01a1ng th\u1ee9c transactional t\u1eeb b\u00ean trong c\u00f9ng m\u1ed9t class.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>T\u1ed1i \u01b0u h\u00f3a truy v\u1ea5n:<\/b><span style=\"font-weight: 400;\"> Spring Data JPA r\u1ea5t ti\u1ec7n l\u1ee3i, nh\u01b0ng \u0111\u00f4i khi c\u00e1c truy v\u1ea5n t\u1ef1 \u0111\u1ed9ng sinh ra kh\u00f4ng t\u1ed1i \u01b0u. S\u1eed d\u1ee5ng JPQL (<\/span><span style=\"font-weight: 400;\">@Query<\/span><span style=\"font-weight: 400;\">), Native Query, ho\u1eb7c Criteria API khi c\u1ea7n ki\u1ec3m so\u00e1t truy v\u1ea5n t\u1ed1t h\u01a1n. B\u1eadt logging SQL \u0111\u1ec3 theo d\u00f5i c\u00e1c c\u00e2u l\u1ec7nh \u0111\u01b0\u1ee3c th\u1ef1c thi. C\u1ea9n th\u1eadn v\u1edbi v\u1ea5n \u0111\u1ec1 N+1 query khi l\u00e0m vi\u1ec7c v\u1edbi c\u00e1c m\u1ed1i quan h\u1ec7 (s\u1eed d\u1ee5ng fetch join ho\u1eb7c <\/span><span style=\"font-weight: 400;\">@EntityGraph<\/span><span style=\"font-weight: 400;\">).<\/span><\/li>\n<\/ul>\n<h3><b>Ch\u00fa tr\u1ecdng B\u1ea3o m\u1eadt (Spring Security)<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Hi\u1ec3u c\u1ea5u h\u00ecnh c\u01a1 b\u1ea3n:<\/b><span style=\"font-weight: 400;\"> N\u1eafm v\u1eefng c\u00e1ch c\u1ea5u h\u00ecnh <\/span><span style=\"font-weight: 400;\">SecurityFilterChain<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 \u0111\u1ecbnh ngh\u0129a c\u00e1c quy t\u1eafc b\u1ea3o m\u1eadt (permitAll, authenticated, hasRole&#8230;).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ch\u1ecdn c\u01a1 ch\u1ebf x\u00e1c th\u1ef1c ph\u00f9 h\u1ee3p:<\/b><span style=\"font-weight: 400;\"> Hi\u1ec3u c\u00e1c l\u1ef1a ch\u1ecdn nh\u01b0 Form Login, Basic Auth, OAuth2\/OIDC, JWT v\u00e0 ch\u1ecdn ph\u01b0\u01a1ng \u00e1n ph\u00f9 h\u1ee3p v\u1edbi y\u00eau c\u1ea7u \u1ee9ng d\u1ee5ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Kh\u00f4ng bao gi\u1edd l\u01b0u m\u1eadt kh\u1ea9u d\u1ea1ng plain text:<\/b><span style=\"font-weight: 400;\"> Lu\u00f4n s\u1eed d\u1ee5ng c\u00e1c c\u01a1 ch\u1ebf m\u00e3 h\u00f3a m\u1ea1nh (nh\u01b0 BCrypt) \u0111\u01b0\u1ee3c cung c\u1ea5p b\u1edfi <\/span><span style=\"font-weight: 400;\">PasswordEncoder<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Lu\u00f4n c\u1eadp nh\u1eadt:<\/b><span style=\"font-weight: 400;\"> Theo d\u00f5i c\u00e1c l\u1ed7 h\u1ed5ng b\u1ea3o m\u1eadt \u0111\u01b0\u1ee3c c\u00f4ng b\u1ed1 cho Spring Security v\u00e0 c\u00e1c th\u01b0 vi\u1ec7n li\u00ean quan, c\u1eadp nh\u1eadt phi\u00ean b\u1ea3n k\u1ecbp th\u1eddi.<\/span><\/li>\n<\/ul>\n<h3><b>Theo d\u00f5i v\u00e0 T\u1ed1i \u01b0u hi\u1ec7u n\u0103ng<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>S\u1eed d\u1ee5ng Spring Boot Actuator:<\/b><span style=\"font-weight: 400;\"> Actuator cung c\u1ea5p c\u00e1c endpoint h\u1eefu \u00edch \u0111\u1ec3 gi\u00e1m s\u00e1t v\u00e0 qu\u1ea3n l\u00fd \u1ee9ng d\u1ee5ng (health, metrics, info, env&#8230;). T\u00edch h\u1ee3p v\u1edbi c\u00e1c h\u1ec7 th\u1ed1ng monitoring nh\u01b0 Prometheus, Grafana.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Profiling:<\/b><span style=\"font-weight: 400;\"> S\u1eed d\u1ee5ng c\u00e1c c\u00f4ng c\u1ee5 profiler (nh\u01b0 VisualVM, JProfiler) \u0111\u1ec3 x\u00e1c \u0111\u1ecbnh c\u00e1c \u0111i\u1ec3m ngh\u1ebdn c\u1ed5 chai (bottlenecks) trong \u1ee9ng d\u1ee5ng khi c\u1ea7n thi\u1ebft.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Caching:<\/b><span style=\"font-weight: 400;\"> C\u00e2n nh\u1eafc s\u1eed d\u1ee5ng caching (v\u00ed d\u1ee5 v\u1edbi Spring Cache Abstraction v\u00e0 EhCache, Redis, Caffeine) cho c\u00e1c d\u1eef li\u1ec7u \u00edt thay \u0111\u1ed5i ho\u1eb7c c\u00e1c t\u00e1c v\u1ee5 t\u1ed1n k\u00e9m t\u00e0i nguy\u00ean.<\/span><\/li>\n<\/ul>\n<h3><b>Li\u00ean t\u1ee5c h\u1ecdc h\u1ecfi v\u00e0 c\u1eadp nh\u1eadt<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Theo d\u00f5i Blog v\u00e0 T\u00e0i li\u1ec7u ch\u00ednh th\u1ee9c:<\/b><span style=\"font-weight: 400;\"> H\u1ec7 sinh th\u00e1i Spring ph\u00e1t tri\u1ec3n r\u1ea5t nhanh. Th\u01b0\u1eddng xuy\u00ean \u0111\u1ecdc blog ch\u00ednh th\u1ee9c c\u1ee7a Spring (<\/span><span style=\"font-weight: 400;\">spring.io\/blog<\/span><span style=\"font-weight: 400;\">), xem t\u00e0i li\u1ec7u c\u00e1c phi\u00ean b\u1ea3n m\u1edbi, v\u00e0 theo d\u00f5i c\u00e1c thay \u0111\u1ed5i quan tr\u1ecdng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Tham gia c\u1ed9ng \u0111\u1ed3ng:<\/b><span style=\"font-weight: 400;\"> H\u1ecdc h\u1ecfi t\u1eeb kinh nghi\u1ec7m c\u1ee7a ng\u01b0\u1eddi kh\u00e1c qua Stack Overflow, c\u00e1c di\u1ec5n \u0111\u00e0n, h\u1ed9i th\u1ea3o, ho\u1eb7c c\u00e1c nh\u00f3m c\u1ed9ng \u0111\u1ed3ng Spring\/Java t\u1ea1i \u0111\u1ecba ph\u01b0\u01a1ng.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">L\u00e0m vi\u1ec7c v\u1edbi Spring l\u00e0 m\u1ed9t h\u00e0nh tr\u00ecnh li\u00ean t\u1ee5c h\u1ecdc h\u1ecfi. B\u1eb1ng c\u00e1ch n\u1eafm v\u1eefng c\u00e1c kh\u00e1i ni\u1ec7m c\u01a1 b\u1ea3n, \u00e1p d\u1ee5ng c\u00e1c best practice, v\u00e0 kh\u00f4ng ng\u1eebng trau d\u1ed3i kinh nghi\u1ec7m th\u1ef1c t\u1ebf, b\u1ea1n s\u1ebd ng\u00e0y c\u00e0ng tr\u1edf n\u00ean th\u00e0nh th\u1ea1o v\u00e0 x\u00e2y d\u1ef1ng \u0111\u01b0\u1ee3c nh\u1eefng \u1ee9ng d\u1ee5ng Java ch\u1ea5t l\u01b0\u1ee3ng cao, \u1ed5n \u0111\u1ecbnh v\u00e0 d\u1ec5 b\u1ea3o tr\u00ec.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cac_cau_hoi_thuong_gap_ve_Spring_Java\"><\/span><span style=\"font-weight: 400;\"><strong>C\u00e1c c\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 Spring Java<\/strong><\/span><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>L\u00e0m th\u1ebf n\u00e0o \u0111\u1ec3 x\u1eed l\u00fd Exception m\u1ed9t c\u00e1ch nh\u1ea5t qu\u00e1n trong \u1ee9ng d\u1ee5ng Spring Web?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">@ControllerAdvice<\/span><span style=\"font-weight: 400;\"> k\u1ebft h\u1ee3p v\u1edbi c\u00e1c ph\u01b0\u01a1ng th\u1ee9c \u0111\u01b0\u1ee3c \u0111\u00e1nh d\u1ea5u <\/span><span style=\"font-weight: 400;\">@ExceptionHandler<\/span><span style=\"font-weight: 400;\">. <\/span><span style=\"font-weight: 400;\">@ControllerAdvice<\/span><span style=\"font-weight: 400;\"> cho ph\u00e9p b\u1ea1n \u0111\u1ecbnh ngh\u0129a m\u1ed9t n\u01a1i t\u1eadp trung \u0111\u1ec3 x\u1eed l\u00fd exception x\u1ea3y ra trong c\u00e1c Controller.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">B\u00ean trong l\u1edbp <\/span><span style=\"font-weight: 400;\">@ControllerAdvice<\/span><span style=\"font-weight: 400;\">, b\u1ea1n vi\u1ebft c\u00e1c ph\u01b0\u01a1ng th\u1ee9c x\u1eed l\u00fd cho t\u1eebng lo\u1ea1i Exception c\u1ee5 th\u1ec3 (<\/span><span style=\"font-weight: 400;\">@ExceptionHandler(SpecificException.class)<\/span><span style=\"font-weight: 400;\">) v\u00e0 tr\u1ea3 v\u1ec1 m\u1ed9t response l\u1ed7i chu\u1ea9n h\u00f3a (v\u00ed d\u1ee5: \u0111\u1ed1i t\u01b0\u1ee3ng JSON ch\u1ee9a m\u00e3 l\u1ed7i, th\u00f4ng b\u00e1o l\u1ed7i).<\/span><\/p>\n<h3><b>T\u1ea1i sao c\u1ea7n m\u00e3 h\u00f3a m\u1eadt kh\u1ea9u v\u00e0 Spring Security h\u1ed7 tr\u1ee3 nh\u01b0 th\u1ebf n\u00e0o?<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>T\u1ea1i sao:<\/b><span style=\"font-weight: 400;\"> L\u01b0u m\u1eadt kh\u1ea9u d\u1ea1ng plain text (v\u0103n b\u1ea3n thu\u1ea7n) l\u00e0 c\u1ef1c k\u1ef3 nguy hi\u1ec3m. N\u1ebfu c\u01a1 s\u1edf d\u1eef li\u1ec7u b\u1ecb x\u00e2m nh\u1eadp, to\u00e0n b\u1ed9 m\u1eadt kh\u1ea9u ng\u01b0\u1eddi d\u00f9ng s\u1ebd b\u1ecb l\u1ed9. M\u00e3 h\u00f3a (ch\u00ednh x\u00e1c h\u01a1n l\u00e0 hashing v\u1edbi salt) bi\u1ebfn m\u1eadt kh\u1ea9u th\u00e0nh m\u1ed9t chu\u1ed7i kh\u00f4ng th\u1ec3 \u0111\u1ea3o ng\u01b0\u1ee3c, gi\u00fap b\u1ea3o v\u1ec7 th\u00f4ng tin ng\u01b0\u1eddi d\u00f9ng ngay c\u1ea3 khi d\u1eef li\u1ec7u b\u1ecb r\u00f2 r\u1ec9.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>H\u1ed7 tr\u1ee3 c\u1ee7a Spring Security:<\/b><span style=\"font-weight: 400;\"> Cung c\u1ea5p interface <\/span><span style=\"font-weight: 400;\">PasswordEncoder<\/span><span style=\"font-weight: 400;\"> v\u00e0 c\u00e1c implementation m\u1ea1nh m\u1ebd nh\u01b0 <\/span><span style=\"font-weight: 400;\">BCryptPasswordEncoder<\/span><span style=\"font-weight: 400;\"> (khuy\u1ebfn ngh\u1ecb), <\/span><span style=\"font-weight: 400;\">Argon2PasswordEncoder<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">Pbkdf2PasswordEncoder<\/span><span style=\"font-weight: 400;\">. B\u1ea1n ch\u1ec9 c\u1ea7n \u0111\u1ecbnh ngh\u0129a m\u1ed9t <\/span><span style=\"font-weight: 400;\">Bean<\/span> <span style=\"font-weight: 400;\">PasswordEncoder<\/span><span style=\"font-weight: 400;\"> trong c\u1ea5u h\u00ecnh, Spring Security s\u1ebd t\u1ef1 \u0111\u1ed9ng s\u1eed d\u1ee5ng n\u00f3 \u0111\u1ec3 m\u00e3 h\u00f3a m\u1eadt kh\u1ea9u khi \u0111\u0103ng k\u00fd v\u00e0 so s\u00e1nh m\u1eadt kh\u1ea9u (\u0111\u00e3 hash) khi \u0111\u0103ng nh\u1eadp.<\/span><\/li>\n<\/ul>\n<h3><b>S\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa Unit Test v\u00e0 Integration Test trong Spring Boot?<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Unit Test:<\/b><span style=\"font-weight: 400;\"> Ki\u1ec3m th\u1eed m\u1ed9t \u0111\u01a1n v\u1ecb code (th\u01b0\u1eddng l\u00e0 m\u1ed9t class) m\u1ed9t c\u00e1ch <\/span><b>c\u00f4 l\u1eadp<\/b><span style=\"font-weight: 400;\">. C\u00e1c dependency b\u00ean ngo\u00e0i \u0111\u01b0\u1ee3c <\/span><b>mock<\/b><span style=\"font-weight: 400;\"> (gi\u1ea3 l\u1eadp) b\u1eb1ng c\u00e1c th\u01b0 vi\u1ec7n nh\u01b0 Mockito. M\u1ee5c ti\u00eau l\u00e0 ki\u1ec3m tra logic n\u1ed9i t\u1ea1i c\u1ee7a class \u0111\u00f3. Kh\u00f4ng c\u1ea7n t\u1ea3i Spring ApplicationContext.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Integration Test:<\/b><span style=\"font-weight: 400;\"> Ki\u1ec3m th\u1eed s\u1ef1 <\/span><b>t\u01b0\u01a1ng t\u00e1c gi\u1eefa nhi\u1ec1u component<\/b><span style=\"font-weight: 400;\"> v\u1edbi nhau ho\u1eb7c v\u1edbi c\u00e1c h\u1ec7 th\u1ed1ng b\u00ean ngo\u00e0i (database, message queue, API kh\u00e1c). Th\u01b0\u1eddng y\u00eau c\u1ea7u t\u1ea3i m\u1ed9t ph\u1ea7n ho\u1eb7c to\u00e0n b\u1ed9 Spring ApplicationContext (<\/span><span style=\"font-weight: 400;\">@SpringBootTest<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">@DataJpaTest<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">@WebMvcTest<\/span><span style=\"font-weight: 400;\">&#8230;). M\u1ee5c ti\u00eau l\u00e0 \u0111\u1ea3m b\u1ea3o c\u00e1c ph\u1ea7n c\u1ee7a \u1ee9ng d\u1ee5ng ho\u1ea1t \u0111\u1ed9ng \u0111\u00fang khi t\u00edch h\u1ee3p l\u1ea1i v\u1edbi nhau<\/span><\/li>\n<\/ul>\n<h3><b>C\u00e1ch t\u1ed1t nh\u1ea5t \u0111\u1ec3 qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh cho nhi\u1ec1u m\u00f4i tr\u01b0\u1eddng (dev, test, prod) l\u00e0 g\u00ec?<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng <\/span><b>Spring Profiles<\/b><span style=\"font-weight: 400;\">. T\u1ea1o c\u00e1c file c\u1ea5u h\u00ecnh ri\u00eang cho t\u1eebng m\u00f4i tr\u01b0\u1eddng (v\u00ed d\u1ee5: <\/span><span style=\"font-weight: 400;\">application-dev.properties<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">application-prod.yml<\/span><span style=\"font-weight: 400;\">). K\u00edch ho\u1ea1t profile t\u01b0\u01a1ng \u1ee9ng khi ch\u1ea1y \u1ee9ng d\u1ee5ng (qua bi\u1ebfn m\u00f4i tr\u01b0\u1eddng <\/span><span style=\"font-weight: 400;\">SPRING_PROFILES_ACTIVE<\/span><span style=\"font-weight: 400;\">, tham s\u1ed1 d\u00f2ng l\u1ec7nh <\/span><span style=\"font-weight: 400;\">&#8211;spring.profiles.active=&#8230;<\/span><span style=\"font-weight: 400;\">, ho\u1eb7c trong <\/span><span style=\"font-weight: 400;\">application.properties<\/span><span style=\"font-weight: 400;\"> ch\u00ednh).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">K\u1ebft h\u1ee3p v\u1edbi vi\u1ec7c <\/span><b>Externalize Configuration<\/b><span style=\"font-weight: 400;\"> (\u0111\u01b0a c\u1ea5u h\u00ecnh ra ngo\u00e0i code) th\u00f4ng qua bi\u1ebfn m\u00f4i tr\u01b0\u1eddng ho\u1eb7c c\u00e1c h\u1ec7 th\u1ed1ng qu\u1ea3n l\u00fd c\u1ea5u h\u00ecnh t\u1eadp trung (Spring Cloud Config, Consul&#8230;) cho c\u00e1c th\u00f4ng tin nh\u1ea1y c\u1ea3m ho\u1eb7c c\u1ea7n thay \u0111\u1ed5i th\u01b0\u1eddng xuy\u00ean m\u00e0 kh\u00f4ng c\u1ea7n build l\u1ea1i \u1ee9ng d\u1ee5ng.<\/span><\/li>\n<\/ul>\n<h3><b>\u01afu \u0111i\u1ec3m c\u1ee7a Spring so v\u1edbi c\u00e1c Java framework kh\u00e1c l\u00e0 g\u00ec?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u01afu \u0111i\u1ec3m ch\u00ednh c\u1ee7a Spring so v\u1edbi c\u00e1c Java framework kh\u00e1c l\u00e0:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>H\u1ec7 sinh th\u00e1i c\u1ef1c k\u1ef3 to\u00e0n di\u1ec7n:<\/b><span style=\"font-weight: 400;\"> Cung c\u1ea5p gi\u1ea3i ph\u00e1p t\u00edch h\u1ee3p s\u1eb5n cho h\u1ea7u h\u1ebft m\u1ecdi nhu c\u1ea7u (Spring Boot, Cloud, Data, Security&#8230;).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Spring Boot:<\/b><span style=\"font-weight: 400;\"> \u0110\u01a1n gi\u1ea3n h\u00f3a m\u1ea1nh m\u1ebd vi\u1ec7c thi\u1ebft l\u1eadp, c\u1ea5u h\u00ecnh v\u00e0 ch\u1ea1y \u1ee9ng d\u1ee5ng Java.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Linh ho\u1ea1t &amp; Module h\u00f3a cao:<\/b><span style=\"font-weight: 400;\"> Cho ph\u00e9p ch\u1ecdn l\u1ef1a v\u00e0 s\u1eed d\u1ee5ng ch\u1ec9 nh\u1eefng ph\u1ea7n c\u1ea7n thi\u1ebft.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>C\u1ed9ng \u0111\u1ed3ng l\u1edbn v\u00e0 T\u00e0i nguy\u00ean d\u1ed3i d\u00e0o:<\/b><span style=\"font-weight: 400;\"> D\u1ec5 h\u1ecdc, d\u1ec5 t\u00ecm s\u1ef1 tr\u1ee3 gi\u00fap v\u00e0 c\u01a1 h\u1ed9i vi\u1ec7c l\u00e0m.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>T\u00ednh \u1ed5n \u0111\u1ecbnh cao:<\/b><span style=\"font-weight: 400;\"> C\u00e1c t\u00ednh n\u0103ng c\u1ed1t l\u00f5i nh\u01b0 DI, AOP, v\u00e0 c\u00e1c l\u1edbp tr\u1eebu t\u01b0\u1ee3ng h\u00f3a \u0111\u00e3 \u0111\u01b0\u1ee3c ki\u1ec3m ch\u1ee9ng qua th\u1eddi gian.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Tong_ket\"><\/span><strong>T\u1ed5ng k\u1ebft<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Spring Framework, v\u1edbi c\u00e1c kh\u00e1i ni\u1ec7m c\u1ed1t l\u00f5i nh\u01b0 DI v\u00e0 AOP, c\u00f9ng h\u1ec7 sinh th\u00e1i m\u1ea1nh m\u1ebd bao g\u1ed3m Spring Boot, Spring Data, v\u00e0 Spring Security, \u0111\u00e3 tr\u1edf th\u00e0nh n\u1ec1n t\u1ea3ng v\u1eefng ch\u1eafc cho ph\u00e1t tri\u1ec3n \u1ee9ng d\u1ee5ng Java hi\u1ec7n \u0111\u1ea1i. N\u00f3 gi\u00fap \u0111\u01a1n gi\u1ea3n h\u00f3a code, t\u0103ng kh\u1ea3 n\u0103ng b\u1ea3o tr\u00ec v\u00e0 t\u00edch h\u1ee3p. \u0110\u1eb7c bi\u1ec7t, Spring Boot gi\u00fap vi\u1ec7c kh\u1edfi t\u1ea1o v\u00e0 ch\u1ea1y \u1ee9ng d\u1ee5ng tr\u1edf n\u00ean d\u1ec5 d\u00e0ng h\u01a1n bao gi\u1edd h\u1ebft.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Vi\u1ec7c th\u00e0nh th\u1ea1o Spring, nh\u1ea5t l\u00e0 Spring Boot, l\u00e0 m\u1ed9t k\u1ef9 n\u0103ng thi\u1ebft y\u1ebfu cho l\u1eadp tr\u00ecnh vi\u00ean Java, m\u1edf ra nhi\u1ec1u c\u01a1 h\u1ed9i v\u00e0 gi\u00fap x\u00e2y d\u1ef1ng \u1ee9ng d\u1ee5ng ch\u1ea5t l\u01b0\u1ee3ng. Hy v\u1ecdng b\u00e0i vi\u1ebft \u0111\u00e3 cung c\u1ea5p n\u1ec1n t\u1ea3ng v\u1eefng ch\u1eafc \u0111\u1ec3 b\u1ea1n ti\u1ebfp t\u1ee5c kh\u00e1m ph\u00e1 v\u00e0 th\u00e0nh c\u00f4ng v\u1edbi Spring.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring Framework n\u1ed5i l\u00ean nh\u01b0 m\u1ed9t gi\u1ea3i ph\u00e1p h\u00e0ng \u0111\u1ea7u \u0111\u1ed1i v\u1edbi c\u00e1c l\u1eadp tr\u00ecnh vi\u00ean Java \u0111ang t\u00ecm ki\u1ebfm ph\u01b0\u01a1ng ph\u00e1p \u0111\u1ec3 t\u1ed1i \u01b0u h\u00f3a v\u00e0 \u0111\u01a1n gi\u1ea3n h\u00f3a qu\u00e1 tr\u00ecnh x\u00e2y d\u1ef1ng \u1ee9ng d\u1ee5ng, b\u1ed5 sung v\u00e0 n\u00e2ng cao n\u0103ng su\u1ea5t b\u1eb1ng m\u1ed9t c\u1ea5u tr\u00fac n\u1ec1n t\u1ea3ng v\u00e0 b\u1ed9 c\u00f4ng c\u1ee5 phong ph\u00fa. [&hellip;]<\/p>\n","protected":false},"author":203,"featured_media":86902,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109,10104],"tags":[],"class_list":["post-86820","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it","category-tai-lieu-java"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.8) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Spring Java l\u00e0 g\u00ec: H\u01b0\u1edbng d\u1eabn chi ti\u1ebft c\u00e1ch b\u1eaft \u0111\u1ea7u v\u1edbi Spring - ITviec Blog<\/title>\n<meta name=\"description\" content=\"Spring Java gi\u00fap l\u1eadp tr\u00ecnh vi\u00ean x\u00e2y app m\u1ea1nh m\u1ebd v\u00e0 t\u1ed1i \u01b0u h\u01a1n. Xem ngay h\u01b0\u1edbng d\u1eabn b\u1eaft \u0111\u1ea7u d\u1ef1 \u00e1n Spring Java theo t\u1eebng b\u01b0\u1edbc chi ti\u1ebft.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itviec.com\/blog\/spring-java-la-gi\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Java l\u00e0 g\u00ec: H\u01b0\u1edbng d\u1eabn chi ti\u1ebft c\u00e1ch b\u1eaft \u0111\u1ea7u v\u1edbi Spring\" \/>\n<meta property=\"og:description\" content=\"Spring Framework n\u1ed5i l\u00ean nh\u01b0 m\u1ed9t gi\u1ea3i ph\u00e1p h\u00e0ng \u0111\u1ea7u \u0111\u1ed1i v\u1edbi c\u00e1c l\u1eadp tr\u00ecnh vi\u00ean Java \u0111ang t\u00ecm ki\u1ebfm ph\u01b0\u01a1ng ph\u00e1p \u0111\u1ec3 t\u1ed1i \u01b0u h\u00f3a v\u00e0 \u0111\u01a1n gi\u1ea3n h\u00f3a qu\u00e1 tr\u00ecnh x\u00e2y\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/spring-java-la-gi\/\" \/>\n<meta property=\"og:site_name\" content=\"ITviec Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ITviec\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-11T07:08:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/spring-java-la-gi-vippro-scaled.png\" \/>\n\t<meta property=\"og:image:width\" content=\"640\" \/>\n\t<meta property=\"og:image:height\" content=\"337\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Tien Tran\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ITviec\" \/>\n<meta name=\"twitter:site\" content=\"@ITviec\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"Tien Tran\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"22 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Spring Java l\u00e0 g\u00ec: H\u01b0\u1edbng d\u1eabn chi ti\u1ebft c\u00e1ch b\u1eaft \u0111\u1ea7u v\u1edbi Spring - ITviec Blog","description":"Spring Java gi\u00fap l\u1eadp tr\u00ecnh vi\u00ean x\u00e2y app m\u1ea1nh m\u1ebd v\u00e0 t\u1ed1i \u01b0u h\u01a1n. Xem ngay h\u01b0\u1edbng d\u1eabn b\u1eaft \u0111\u1ea7u d\u1ef1 \u00e1n Spring Java theo t\u1eebng b\u01b0\u1edbc chi ti\u1ebft.","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:\/\/itviec.com\/blog\/spring-java-la-gi\/","og_locale":"vi_VN","og_type":"article","og_title":"Spring Java l\u00e0 g\u00ec: H\u01b0\u1edbng d\u1eabn chi ti\u1ebft c\u00e1ch b\u1eaft \u0111\u1ea7u v\u1edbi Spring","og_description":"Spring Framework n\u1ed5i l\u00ean nh\u01b0 m\u1ed9t gi\u1ea3i ph\u00e1p h\u00e0ng \u0111\u1ea7u \u0111\u1ed1i v\u1edbi c\u00e1c l\u1eadp tr\u00ecnh vi\u00ean Java \u0111ang t\u00ecm ki\u1ebfm ph\u01b0\u01a1ng ph\u00e1p \u0111\u1ec3 t\u1ed1i \u01b0u h\u00f3a v\u00e0 \u0111\u01a1n gi\u1ea3n h\u00f3a qu\u00e1 tr\u00ecnh x\u00e2y","og_url":"https:\/\/itviec.com\/blog\/spring-java-la-gi\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2025-05-11T07:08:42+00:00","og_image":[{"width":640,"height":337,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/spring-java-la-gi-vippro-scaled.png","type":"image\/png"}],"author":"Tien Tran","twitter_card":"summary_large_image","twitter_creator":"@ITviec","twitter_site":"@ITviec","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"Tien Tran","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"22 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/spring-java-la-gi\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/spring-java-la-gi\/"},"author":{"name":"Tien Tran","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/1595d671c49cfa2a48cd3c0a047a1298"},"headline":"Spring Java l\u00e0 g\u00ec: H\u01b0\u1edbng d\u1eabn chi ti\u1ebft c\u00e1ch b\u1eaft \u0111\u1ea7u v\u1edbi Spring","datePublished":"2025-05-11T07:08:42+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/spring-java-la-gi\/"},"wordCount":5773,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/spring-java-la-gi\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/spring-java-la-gi-vippro-scaled.png","articleSection":["Chuy\u00ean m\u00f4n IT","T\u00e0i li\u1ec7u Java"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/spring-java-la-gi\/","url":"https:\/\/itviec.com\/blog\/spring-java-la-gi\/","name":"Spring Java l\u00e0 g\u00ec: H\u01b0\u1edbng d\u1eabn chi ti\u1ebft c\u00e1ch b\u1eaft \u0111\u1ea7u v\u1edbi Spring - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/spring-java-la-gi\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/spring-java-la-gi\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/spring-java-la-gi-vippro-scaled.png","datePublished":"2025-05-11T07:08:42+00:00","description":"Spring Java gi\u00fap l\u1eadp tr\u00ecnh vi\u00ean x\u00e2y app m\u1ea1nh m\u1ebd v\u00e0 t\u1ed1i \u01b0u h\u01a1n. Xem ngay h\u01b0\u1edbng d\u1eabn b\u1eaft \u0111\u1ea7u d\u1ef1 \u00e1n Spring Java theo t\u1eebng b\u01b0\u1edbc chi ti\u1ebft.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/spring-java-la-gi\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/spring-java-la-gi\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/spring-java-la-gi\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/spring-java-la-gi-vippro-scaled.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/05\/spring-java-la-gi-vippro-scaled.png","width":640,"height":337,"caption":"spring java l\u00e0 g\u00ec - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/spring-java-la-gi\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Chuy\u00ean m\u00f4n IT","item":"https:\/\/itviec.com\/blog\/chuyen-mon-it\/"},{"@type":"ListItem","position":2,"name":"Spring Java l\u00e0 g\u00ec: H\u01b0\u1edbng d\u1eabn chi ti\u1ebft c\u00e1ch b\u1eaft \u0111\u1ea7u v\u1edbi Spring"}]},{"@type":"WebSite","@id":"https:\/\/itviec.com\/blog\/#website","url":"https:\/\/itviec.com\/blog\/","name":"ITviec Blog","description":"IT Jobs &amp; People in Vietnam","publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itviec.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/itviec.com\/blog\/#organization","name":"ITviec","url":"https:\/\/itviec.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","width":1800,"height":1800,"caption":"ITviec"},"image":{"@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ITviec","https:\/\/x.com\/ITviec","https:\/\/www.linkedin.com\/company\/itviec","https:\/\/www.youtube.com\/channel\/UCYthAQ3bcGr57M_ag5gHDvQ"]},{"@type":"Person","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/1595d671c49cfa2a48cd3c0a047a1298","name":"Tien Tran","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/05\/tien-tran-author-e1715658627643-100x100.jpg","caption":"Tien Tran"},"url":"https:\/\/itviec.com\/blog\/author\/tien-tran\/"}]}},"_links":{"self":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/86820","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/users\/203"}],"replies":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/comments?post=86820"}],"version-history":[{"count":0,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/86820\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/86902"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=86820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=86820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=86820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}