{"id":1,"date":"2022-09-03T21:55:07","date_gmt":"2022-09-03T21:55:07","guid":{"rendered":"http:\/\/box2111\/cgi\/addon_GT.cgi?s=GT::WP::Install::EIG+%28codebodh%29+-+10.24.48.80+%5BWordpress%3b+\/var\/hp\/common\/lib\/Wordpress.pm%3b+543%3b+Hosting::gap_call%5D\/?p=1"},"modified":"2022-09-20T03:31:32","modified_gmt":"2022-09-20T03:31:32","slug":"lombok","status":"publish","type":"post","link":"https:\/\/codebodhi.com\/?p=1","title":{"rendered":"Lombok &#038; Spring framework"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/projectlombok.org\">Lombok<\/a> is a widely used Java library to eliminate boilerplate code for setters, getters, Equals &amp; Hashcode etc. The focus of this article is go over some of the Lombok annotations when used with SpringBoot framework.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"text-decoration: underline;\">Constructor Injection<\/span>: Spring allows injecting mandatory dependencies via constructor which is the most preferred way. Let&#8217;s look at Listing 1 below,  that declares a Spring service class that has 2 dependencies via dependency1,  dependency2 both injected via constructor. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">  Listing 1:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>@Service\nclass Service {\n   private Dependency1 dependency1;\n   private Dependency2 dependency2;\n   \n   @Autowired \n   public class Service(Dependency1 dependency1, Dependency1 dependency2) {\n       this.dependency1 = dependency1;\n       this.dependency2 = dependency2;\n  }\n}<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s see how  Listing 1 can be updated to use Lombok annotations in Listing 2. It uses @RequiredAllArgsConstructor annotation which signals that all the instance variables are final and initialized through constructor, when this annotation is used in conjunction with @Service Spring will inject them through the constructor.   <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> Listing 2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>@Service\n@RequiredAllArgsConstructor\nclass Service {\n   private final Dependency1 dependency1;\n   private final Dependency1 dependency2;\n}<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"mb-2\">Lombok is a widely used Java library to eliminate boilerplate code for setters, getters, Equals &amp; Hashcode etc. The focus of this article is go over some of the Lombok annotations when used with SpringBoot framework. Constructor Injection: Spring allows injecting mandatory dependencies via constructor which is the most preferred way. Let&#8217;s look at Listing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[3,4,5],"class_list":["post-1","post","type-post","status-publish","format-standard","hentry","category-java","tag-lombok","tag-spring","tag-springboot"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Lombok &amp; Spring framework - CodeBodhi<\/title>\n<meta name=\"description\" content=\"lombok\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codebodhi.com\/?p=1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Lombok &amp; Spring framework - CodeBodhi\" \/>\n<meta property=\"og:description\" content=\"lombok\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codebodhi.com\/?p=1\" \/>\n<meta property=\"og:site_name\" content=\"CodeBodhi\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-03T21:55:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-20T03:31:32+00:00\" \/>\n<meta name=\"author\" content=\"codebodhi\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"codebodhi\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/codebodhi.com\\\/?p=1#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codebodhi.com\\\/?p=1\"},\"author\":{\"name\":\"codebodhi\",\"@id\":\"https:\\\/\\\/codebodhi.com\\\/#\\\/schema\\\/person\\\/465cc918aa582699c4fb9309f3fb99cb\"},\"headline\":\"Lombok &#038; Spring framework\",\"datePublished\":\"2022-09-03T21:55:07+00:00\",\"dateModified\":\"2022-09-20T03:31:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/codebodhi.com\\\/?p=1\"},\"wordCount\":125,\"commentCount\":0,\"keywords\":[\"lombok\",\"Spring\",\"SpringBoot\"],\"articleSection\":[\"Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/codebodhi.com\\\/?p=1#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/codebodhi.com\\\/?p=1\",\"url\":\"https:\\\/\\\/codebodhi.com\\\/?p=1\",\"name\":\"Lombok & Spring framework - CodeBodhi\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/codebodhi.com\\\/#website\"},\"datePublished\":\"2022-09-03T21:55:07+00:00\",\"dateModified\":\"2022-09-20T03:31:32+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/codebodhi.com\\\/#\\\/schema\\\/person\\\/465cc918aa582699c4fb9309f3fb99cb\"},\"description\":\"lombok\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/codebodhi.com\\\/?p=1#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/codebodhi.com\\\/?p=1\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/codebodhi.com\\\/?p=1#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/codebodhi.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Lombok &#038; Spring framework\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/codebodhi.com\\\/#website\",\"url\":\"https:\\\/\\\/codebodhi.com\\\/\",\"name\":\"CodeBodhi\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/codebodhi.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/codebodhi.com\\\/#\\\/schema\\\/person\\\/465cc918aa582699c4fb9309f3fb99cb\",\"name\":\"codebodhi\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/eb5bec0494ba6059277efd137ba66488296ae637122f8fc8ec58b6b4dafd188d?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/eb5bec0494ba6059277efd137ba66488296ae637122f8fc8ec58b6b4dafd188d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/eb5bec0494ba6059277efd137ba66488296ae637122f8fc8ec58b6b4dafd188d?s=96&d=mm&r=g\",\"caption\":\"codebodhi\"},\"url\":\"https:\\\/\\\/codebodhi.com\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Lombok & Spring framework - CodeBodhi","description":"lombok","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:\/\/codebodhi.com\/?p=1","og_locale":"en_US","og_type":"article","og_title":"Lombok & Spring framework - CodeBodhi","og_description":"lombok","og_url":"https:\/\/codebodhi.com\/?p=1","og_site_name":"CodeBodhi","article_published_time":"2022-09-03T21:55:07+00:00","article_modified_time":"2022-09-20T03:31:32+00:00","author":"codebodhi","twitter_card":"summary_large_image","twitter_misc":{"Written by":"codebodhi","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/codebodhi.com\/?p=1#article","isPartOf":{"@id":"https:\/\/codebodhi.com\/?p=1"},"author":{"name":"codebodhi","@id":"https:\/\/codebodhi.com\/#\/schema\/person\/465cc918aa582699c4fb9309f3fb99cb"},"headline":"Lombok &#038; Spring framework","datePublished":"2022-09-03T21:55:07+00:00","dateModified":"2022-09-20T03:31:32+00:00","mainEntityOfPage":{"@id":"https:\/\/codebodhi.com\/?p=1"},"wordCount":125,"commentCount":0,"keywords":["lombok","Spring","SpringBoot"],"articleSection":["Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/codebodhi.com\/?p=1#respond"]}]},{"@type":"WebPage","@id":"https:\/\/codebodhi.com\/?p=1","url":"https:\/\/codebodhi.com\/?p=1","name":"Lombok & Spring framework - CodeBodhi","isPartOf":{"@id":"https:\/\/codebodhi.com\/#website"},"datePublished":"2022-09-03T21:55:07+00:00","dateModified":"2022-09-20T03:31:32+00:00","author":{"@id":"https:\/\/codebodhi.com\/#\/schema\/person\/465cc918aa582699c4fb9309f3fb99cb"},"description":"lombok","breadcrumb":{"@id":"https:\/\/codebodhi.com\/?p=1#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codebodhi.com\/?p=1"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codebodhi.com\/?p=1#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codebodhi.com\/"},{"@type":"ListItem","position":2,"name":"Lombok &#038; Spring framework"}]},{"@type":"WebSite","@id":"https:\/\/codebodhi.com\/#website","url":"https:\/\/codebodhi.com\/","name":"CodeBodhi","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codebodhi.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/codebodhi.com\/#\/schema\/person\/465cc918aa582699c4fb9309f3fb99cb","name":"codebodhi","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/eb5bec0494ba6059277efd137ba66488296ae637122f8fc8ec58b6b4dafd188d?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/eb5bec0494ba6059277efd137ba66488296ae637122f8fc8ec58b6b4dafd188d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eb5bec0494ba6059277efd137ba66488296ae637122f8fc8ec58b6b4dafd188d?s=96&d=mm&r=g","caption":"codebodhi"},"url":"https:\/\/codebodhi.com\/?author=1"}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/codebodhi.com\/index.php?rest_route=\/wp\/v2\/posts\/1","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codebodhi.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codebodhi.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codebodhi.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codebodhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1"}],"version-history":[{"count":5,"href":"https:\/\/codebodhi.com\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions"}],"predecessor-version":[{"id":23,"href":"https:\/\/codebodhi.com\/index.php?rest_route=\/wp\/v2\/posts\/1\/revisions\/23"}],"wp:attachment":[{"href":"https:\/\/codebodhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codebodhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codebodhi.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}