{"id":88249,"date":"2019-02-13T07:00:52","date_gmt":"2019-02-13T05:00:52","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=88249"},"modified":"2019-02-18T14:19:41","modified_gmt":"2019-02-18T12:19:41","slug":"spring-dependency-injection-inversion-control","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html","title":{"rendered":"Spring Dependency Injection and Inversion of Control"},"content":{"rendered":"<p>Learn the concepts of Dependency Injection and Inversion of Control and then look into how the Spring Framework supports them with the help of code examples.<\/p>\n<h3 class=\"wp-block-heading\">Inversion Of Control<\/h3>\n<p>Before we start off with anything, let\u2019s learn what the <strong>Inversion&nbsp;of&nbsp;Control<\/strong> is. <br \/>The Inversion of control is a term used in Object Oriented Programming, by which the control of an object or set of objects is given to a framework or a container provided by the framework.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"773\" height=\"562\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/02\/1.jpg\" alt=\"Spring Dependency Injection\" class=\"wp-image-88271\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/02\/1.jpg 773w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/02\/1-300x218.jpg 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/02\/1-768x558.jpg 768w\" sizes=\"(max-width: 773px) 100vw, 773px\" \/><\/figure>\n<\/div>\n<p>Although, the above image intends humour, it describes what is <em>Inversion of Control<\/em>. If we consider humans as a software component or a service, they are meant to perform the actions like wake up, go to meeting, or pay bills. For the other things like Keeping track of meetings, to set up alarms or reminders humans use Phones or any smart devices.<\/p>\n<p><b><i>More on Spring Dependency Injection:<\/i><\/b><\/p>\n<ul class=\"wp-block-list\">\n<li><a href=\"http:\/\/www.amitph.com\/spring-setter-injection-example\/\">Spring Setter Dependency Injection Example<\/a><\/li>\n<li><a href=\"http:\/\/www.amitph.com\/spring-field-injection-example\/\">Spring Constructor Dependency Injection Example<\/a><\/li>\n<li><a href=\"http:\/\/www.amitph.com\/spring-field-setter-constructor-injection\/\">Spring Field Dependency Injection Example<\/a><\/li>\n<li><a href=\"http:\/\/www.amitph.com\/spring-dependency-injection-inversion-control\/\">Spring Dependency Injection \u2013 Field vs Setter vs Constructor Injection<\/a><\/li>\n<\/ul>\n<p><em>Spring Inversion of Control<\/em> is similar. We want our software components to do their given jobs. We take configurations and dependencies out of the components and give them to a container called as <strong>Inversion of Control Container<\/strong> or IOC Container. More to come in the below sections.<\/p>\n<p><b>Want to learn more about Spring Framework ?<\/b><\/p>\n<p>Read this:<\/p>\n<ul class=\"wp-block-list\">\n<li><a href=\"http:\/\/www.amitph.com\/introduction-to-spring-framework\/\">Introduction to Spring Framework<\/a><\/li>\n<li><a href=\"http:\/\/www.amitph.com\/spring-framework-architecture\/\">Spring Framework Architecture<\/a><\/li>\n<li><a href=\"http:\/\/www.amitph.com\/spring-boot-rest-service\/\">Spring Boot Rest Service <\/a><\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">What is a Dependency ?<\/h3>\n<p>An application is made up of multiple classes. <em>Usually, each class should have its own dedicated responsibility.<\/em> This results in our classes integrating with different classes to get certain functionality done. When a class A calls a method of class B. Then Class A is <strong>dependent<\/strong> on Class B.<\/p>\n<h2 class=\"wp-block-heading\">Tightly Coupled Objects<\/h2>\n<p>Learn how having a dependency can cause <em>Tightly Coupled Objects<\/em> problem. See the below code.<\/p>\n<p>This is a <code>FileUploadService<\/code> which grabs a file, checks if the file has one of the expected extensions and asks a <code>FileStorageService<\/code> to store the file.<\/p>\n<pre class=\"brush:java\">\npublic class FileUploadService {\n \n    private List&lt;String&gt; validFiles = Arrays.asList(\"xls\", \"doc\".\"txt\", \"ppt\");\n    private FileStorageService service = new AzureBlobStorageService();\n \n    public FileUploadService() {}\n \n    \/\/\n    \/\/ Other methods\n    \/\/\n}\n<\/pre>\n<p>In the code above, we are using <em>Program&nbsp;to&nbsp;Interface<\/em> principle to instantiate <code>FileStorageService<\/code>. But still, the respective implementation is hard-coded in the class. Also the <code>validFiles<\/code> is hard-coded. Both of them are causing a <em>Tightly&nbsp;Coupled<\/em> objects.<\/p>\n<h2 class=\"wp-block-heading\">Loosely Coupled Objects<\/h2>\n<p>Let\u2019s update the <code>FileUploadService<\/code> a bit and we will get <em>Loosely&nbsp;Coupled<\/em> objects.<\/p>\n<pre class=\"brush:java\">\npublic class FileUploadService {\n \n    private List&lt;String&gt; validFiles;\n    private FileStorageService service;\n    \n    public FileUploadService(List&lt;String&gt; validFiles, FileStorageService service){\n        this.validFiles = validFiles;\n        this.service = service;\n    }\n}\n \nclass User {\n    public static void main(String[] ar) {\n        List&lt;String&gt; validFiles = Arrays.asList(\"xls\", \"ppt\", \"doc\");\n        FileStorageService service = new AzureBlobStorageService();\n        \n        FileUploadService fileUploadService = new FileUploadService(validFiles, service);\n    }\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line #3: The variable is declared and not initialised. No hardcoded value.<\/li>\n<li>Line #4: Only a reference to <code>FileStorageService<\/code> type. No implementation attached.<\/li>\n<li>Line #6: All arguments constructor.<\/li>\n<\/ul>\n<p>Let\u2019s see what is happening in <code>User<\/code> class, which is actually the user of <code>FileUploadService<\/code>.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<ul class=\"wp-block-list\">\n<li>Line #17: The <code>FileUploadService<\/code> instance is created by passing all the required arguments to constructor.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\">Dependency Injection<\/h3>\n<p>What we just did is called as <strong>Dependency&nbsp;Injection<\/strong>.<\/p>\n<p>The <strong>Dependency Injection<\/strong> is a term used in <em>Object&nbsp;Oriented&nbsp;Programming<\/em>, by which Objects will focus on doing the assigned functionality and utilising other objects. The necessary configurations and initialisations will not be handled by the objects. However, the Objects will provide a way to initialise them and their dependencies by field assignment, field setters or constructors. This way, the external entities can initialise the things and not the actual objects.<\/p>\n<p>In a Spring based application, <strong>Inversion of Control Container<\/strong> (IoC container) does the dependency injection. We will see that in coming section. First, let\u2019s see why do we even need such a container.<\/p>\n<h3 class=\"wp-block-heading\">Why do we Need an IoC Container ?<\/h3>\n<p>I have modified the previous code example. It is now a <code>ResumeUploaderService<\/code>. A <code>Candidate<\/code> can share its resume to the <code>ResumeUploaderService<\/code>. The service should, upon verifying the extension, share it to a <code>ResumeStorageService<\/code>. As per the organisations current strategy the resumes are being stored in a confidential folder of file system (by <code>FileSystemResumeStorageService<\/code>).<\/p>\n<pre class=\"brush:java\">\npublic class ResumeUploaderService {\n \n    private List&lt;String&gt; validFiles;\n    private ResumeStorageService service;\n \n    public ResumeUploaderService(List&lt;String&gt; validFiles, ResumeStorageService service) {\n        this.validFiles = validFiles;\n        this.service = service;\n    }\n}\n \n \nclass Candidate {\n    public static void main(String[] ar) {\n        List&lt;String&gt; validFiles = Arrays.asList(\"pdf\", \"doc\");\n \n        String filePath = \"\/Users\/app\/confidential\/storage\/resume\";\n        ResumeStorageService service = new FileSystemResumeStorageService(filePath);\n \n        ResumeUploaderService fileUploadService = new ResumeUploaderService(validFiles, service);\n    }\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line #4: <code>ResumeUploaderService<\/code> <em>has-a<\/em> reference to <code>ResumeStorageService<\/code>.<\/li>\n<li>Line #6: Constructor which accepts and sets an implementation of <code>ResumeStorageService<\/code>.<\/li>\n<\/ul>\n<p>To upload a resume the <code>Candidate<\/code> has to instantiate <code>ResumeUploaderService<\/code> and pass resume. But with all the <code>dependency injection<\/code> thing, Candidate\u2019s job has become difficult. Candidate will not only have to instantiate <code>ResumeUploaderService<\/code> but also <code>ResumeStorageService<\/code>. Because, the former cannot be instantiated without the later.<\/p>\n<ul class=\"wp-block-list\">\n<li>Line #17: The candidate decides where to store the resume (I know..its funny !!)<\/li>\n<li>Line #18: Candidate decides whether to use <code>FileSystemResumeStorageService<\/code> or <code>AzureBlobStorageService<\/code>.<\/li>\n<li>Line #20: Finally, candidate instantiates the <code>ResumeUploaderService<\/code>.<\/li>\n<\/ul>\n<p><strong>Below are the important issues with above<\/strong><\/p>\n<ul class=\"wp-block-list\">\n<li>Consumer knows too much.<\/li>\n<li>Consumer, instead of using the service, also initialising it.<\/li>\n<li>Consumer shouldn\u2019t worry how <code>ResumeUploaderService<\/code> doing its job (lack of abstraction).<\/li>\n<li>The ultimate-end consumer, we have to know everything and will have to initialise everything in the system.<\/li>\n<\/ul>\n<p>This clearly indicates, we need something that can take care of all the configurations and initialisations. Something, whose sole responsibility is to manage the initialisations.<\/p>\n<h3 class=\"wp-block-heading\">Inversion of Control Container (IoC Container)<\/h3>\n<p>Spring provides an IoC Container to solve the problem. This container instantiates all the objects, and while doing so it also resolves their dependencies. The class <code>ApplicationContext<\/code> represents the Spring IOC Container. The Application context is responsible for instantiating, configuring and wiring the beans. <br \/><em>Remember, Beans are nothing but Java objects registered with Spring\u2019s Application Context. <\/em><\/p>\n<p>To configure, instantiate or write beans the Application Context needs some instructions. These instructions can be provided in the form of XML configurations, Java Annotations or Code.<\/p>\n<h3 class=\"wp-block-heading\">Spring Dependency Injection<\/h3>\n<p>In <strong>Spring<\/strong> each object is a bean. Each object has an <code>id<\/code>, or <code>name<\/code>. An <strong>ApplicationContext<\/strong> keeps track of all such beens and ids. When a bean is requested, by a consumer, the Application Context returns an instance of the bean. Look at the below code to understand bean creation and wiring in detail.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"706\" height=\"569\" src=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/02\/2.jpg\" alt=\"Spring Dependency Injection\" class=\"wp-image-88272\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/02\/2.jpg 706w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2019\/02\/2-300x242.jpg 300w\" sizes=\"(max-width: 706px) 100vw, 706px\" \/><\/figure>\n<\/div>\n<pre class=\"brush:java\">\nimport org.springframework.beans.factory.annotation.Value;\nimport org.springframework.stereotype.Component;\n \n@Component(\"resumeStorageService\")\npublic class FileSystemResumeStorageService implements ResumeStorageService {\n \n    @Value(\"${resume.storage.path}\")\n    private String storagePath;             \/\/ Storage path assigned based on properties file\n \n    \/\/\n    \/\/ Skipped methods\n    \/\/\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line #4: Tells Spring to register this class as a Bean and identify it by the given name. If name is not provided the class name is considered as identifier.<\/li>\n<li>Line #8: The storage path is now directly injected from a properties file. No need for a consumer to pass it.<\/li>\n<\/ul>\n<pre class=\"brush:java\">\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.beans.factory.annotation.Qualifier;\nimport org.springframework.stereotype.Component;\n \n@Component\npublic class ResumeUploaderService {\n \n    @Autowired\n    @Qualifier(\"resumeStorageService\")\n    private ResumeStorageService storageService;\n \n \n    public ResumeUploaderService(ResumeStorageService storageService) {\n        this.storageService = storageService;\n    }\n \n    \/\/\n    \/\/ Skipped methods\n    \/\/\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line #5: Declares the class as a Spring Bean and class name as identifier.<\/li>\n<li>Line #10: Tells spring to Auto Wire the <code>ResumeStorageService<\/code> implementation which is identified by <code>\"resumeStorageService\"<\/code>.<\/li>\n<\/ul>\n<p>If we want to attach a different implementation of <code>ResumeStorageService<\/code> the <code>ResumeUploaderService<\/code> is not going to change at all.<\/p>\n<pre class=\"brush:java\">\nimport org.springframework.beans.factory.annotation.Autowired;\n \npublic class Candidate {\n    @Autowired private ResumeUploaderService resumeUploaderService;\n \n    public void upload(Byte[] resume) {\n        resumeUploaderService.uploadResume(resume);\n    }\n}\n<\/pre>\n<ul class=\"wp-block-list\">\n<li>Line #4: Asks Spring to assign an instance of <code>resumeUploaderService<\/code>.<\/li>\n<\/ul>\n<p>Everything is so clean and focused. No class is initialising another class or setting any configuration for another class. Everything is managed by Spring\u2019s <strong>Inversion of Control Container (IoC Container)<\/strong>.<\/p>\n<h3 class=\"wp-block-heading\">Summary<\/h3>\n<p>You have come to an end of of the <strong>Spring Dependency Injection and Inversion of Control<\/strong> guide. You learnt what is <strong>Dependency<\/strong> and how classes can be <em>Tightly Coupled<\/em> or <em>Loosely Coupled<\/em>. We understood the concepts of <strong>Dependency Injection<\/strong> and I<strong>nversion Of Control<\/strong> in an <em>Object Oriented Programming<\/em>. You also learnt that <strong>Spring<\/strong>\u2018s <strong>Inversion of Control Container<\/strong> (IoC Container) manages all the <strong>Dependency<\/strong> Injections in our Spring Application.<\/p>\n<p>There are still plenty of things to learn about Springs Dependency Injection. We will cover them in sub ubsequent tutorials.<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>Published on Java Code Geeks with permission by Amit Phaltankar, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener\">JCG program<\/a>. See the original article here: <a href=\"http:\/\/www.amitph.com\/spring-dependency-injection-inversion-control\/\" target=\"_blank\" rel=\"noopener\">Spring Dependency Injection and Inversion of Control<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learn the concepts of Dependency Injection and Inversion of Control and then look into how the Spring Framework supports them with the help of code examples. Inversion Of Control Before we start off with anything, let\u2019s learn what the Inversion&nbsp;of&nbsp;Control is. The Inversion of control is a term used in Object Oriented Programming, by which &hellip;<\/p>\n","protected":false},"author":75543,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30],"class_list":["post-88249","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring Dependency Injection and Inversion of Control - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn about Spring Dependency Injection? Check our article explaining about Spring Dependency Injection and Inversion of Control.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Dependency Injection and Inversion of Control - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about Spring Dependency Injection? Check our article explaining about Spring Dependency Injection and Inversion of Control.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/amit.ph01\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-13T05:00:52+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-18T12:19:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Amit Phaltankar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@amitrph\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Amit Phaltankar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/02\\\/spring-dependency-injection-inversion-control.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/02\\\/spring-dependency-injection-inversion-control.html\"},\"author\":{\"name\":\"Amit Phaltankar\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/11579ea8a790900129c1010a304fe1a9\"},\"headline\":\"Spring Dependency Injection and Inversion of Control\",\"datePublished\":\"2019-02-13T05:00:52+00:00\",\"dateModified\":\"2019-02-18T12:19:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/02\\\/spring-dependency-injection-inversion-control.html\"},\"wordCount\":1174,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/02\\\/spring-dependency-injection-inversion-control.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/02\\\/spring-dependency-injection-inversion-control.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/02\\\/spring-dependency-injection-inversion-control.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/02\\\/spring-dependency-injection-inversion-control.html\",\"name\":\"Spring Dependency Injection and Inversion of Control - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/02\\\/spring-dependency-injection-inversion-control.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/02\\\/spring-dependency-injection-inversion-control.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2019-02-13T05:00:52+00:00\",\"dateModified\":\"2019-02-18T12:19:41+00:00\",\"description\":\"Interested to learn about Spring Dependency Injection? Check our article explaining about Spring Dependency Injection and Inversion of Control.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/02\\\/spring-dependency-injection-inversion-control.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/02\\\/spring-dependency-injection-inversion-control.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/02\\\/spring-dependency-injection-inversion-control.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2019\\\/02\\\/spring-dependency-injection-inversion-control.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Spring Dependency Injection and Inversion of Control\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/11579ea8a790900129c1010a304fe1a9\",\"name\":\"Amit Phaltankar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/414fb2f44cac7c1d28c9f0e9f0532036dc1bb60eda56a77c0285459f1dea8df8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/414fb2f44cac7c1d28c9f0e9f0532036dc1bb60eda56a77c0285459f1dea8df8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/414fb2f44cac7c1d28c9f0e9f0532036dc1bb60eda56a77c0285459f1dea8df8?s=96&d=mm&r=g\",\"caption\":\"Amit Phaltankar\"},\"description\":\"Amit Phaltankar is a Technology enthusiast who has huge passion for sharing what he knows. Amit works as a Java Technology Lead and has huge experience in Programming, Unit Testing, OOAD, Functional Programming, Big Data Technologies, micro-services, and Databases.\",\"sameAs\":[\"http:\\\/\\\/www.amitph.com\\\/\",\"https:\\\/\\\/www.facebook.com\\\/amit.ph01\",\"https:\\\/\\\/au.linkedin.com\\\/in\\\/amitph\",\"https:\\\/\\\/x.com\\\/amitrph\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/amit-phaltankar\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Dependency Injection and Inversion of Control - Java Code Geeks","description":"Interested to learn about Spring Dependency Injection? Check our article explaining about Spring Dependency Injection and Inversion of Control.","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:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html","og_locale":"en_US","og_type":"article","og_title":"Spring Dependency Injection and Inversion of Control - Java Code Geeks","og_description":"Interested to learn about Spring Dependency Injection? Check our article explaining about Spring Dependency Injection and Inversion of Control.","og_url":"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/amit.ph01","article_published_time":"2019-02-13T05:00:52+00:00","article_modified_time":"2019-02-18T12:19:41+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Amit Phaltankar","twitter_card":"summary_large_image","twitter_creator":"@amitrph","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Amit Phaltankar","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html"},"author":{"name":"Amit Phaltankar","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/11579ea8a790900129c1010a304fe1a9"},"headline":"Spring Dependency Injection and Inversion of Control","datePublished":"2019-02-13T05:00:52+00:00","dateModified":"2019-02-18T12:19:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html"},"wordCount":1174,"commentCount":1,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html","url":"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html","name":"Spring Dependency Injection and Inversion of Control - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2019-02-13T05:00:52+00:00","dateModified":"2019-02-18T12:19:41+00:00","description":"Interested to learn about Spring Dependency Injection? Check our article explaining about Spring Dependency Injection and Inversion of Control.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2019\/02\/spring-dependency-injection-inversion-control.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Spring Dependency Injection and Inversion of Control"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/11579ea8a790900129c1010a304fe1a9","name":"Amit Phaltankar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/414fb2f44cac7c1d28c9f0e9f0532036dc1bb60eda56a77c0285459f1dea8df8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/414fb2f44cac7c1d28c9f0e9f0532036dc1bb60eda56a77c0285459f1dea8df8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/414fb2f44cac7c1d28c9f0e9f0532036dc1bb60eda56a77c0285459f1dea8df8?s=96&d=mm&r=g","caption":"Amit Phaltankar"},"description":"Amit Phaltankar is a Technology enthusiast who has huge passion for sharing what he knows. Amit works as a Java Technology Lead and has huge experience in Programming, Unit Testing, OOAD, Functional Programming, Big Data Technologies, micro-services, and Databases.","sameAs":["http:\/\/www.amitph.com\/","https:\/\/www.facebook.com\/amit.ph01","https:\/\/au.linkedin.com\/in\/amitph","https:\/\/x.com\/amitrph"],"url":"https:\/\/www.javacodegeeks.com\/author\/amit-phaltankar"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/88249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/75543"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=88249"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/88249\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=88249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=88249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=88249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}