[Music] introduction no next one t what is what is dependency injection what is dependency injection team how many types of dependency injections types of dependency injections next one team how to configure how to configure dependency injection how to configure dependency injection in spring a using xml market no one will use this ok xml b java config still people are using whatever annotations approach connotation approach we are going into city okay example sun okay example sun around 25 examples we are going to see examples on only xml examples are only xml examples on only java config examples on only using pure annotations and examples on the combination of xml plus java config combination of xml plus java config plus annotations around 25 examples we are going into ct 25 at the end of the course now okay fifth one fifth one very very important concept in is called scope steam in spring core how many scopes are there two scopes are there when to use singleton and to use prototype team okay now 61 t okay six to one t very very important how to load the properties file hey please go on mute how to load the properties file team how to load the properties file using spring core seventh one team profiles is very very important in our real time we have different profiles are there devops profiles okay environments test our uad or production how to load this properties file using the profile concept team now eighth one okay okay one we are going to see we are going to see how to apply spring core in web applications ninth one spring aware interfaces t spring b aware interfaces last one last one spring bean lifecycle these are the topics we are going to discuss these two days at the end of the course so you will get at the end of the course you will get once course will look successful you will get class notes plus 25 examples what are the examples we are going to discuss here these 25 examples we are going to provide to ut so that you would be okay practice all these things while doing practicing if any questions also you can send email to sreenu.sinotech at the red so that not immediate response you can expect maybe one day delay because i am working classes plus working day i may or no oh yeah you cannot expect the real time response you will be expecting some 24 hours okay within 24 hours you will be expecting a response t okay at the end if you are interested if you are good we are going to discuss faq also top some 20 faqs of spring core we are going to discuss recording will not share team recording will not share i have clearly here mentioned right you will get class notes plus 25 examples if any technical you can send here understood t okay now let's start team so what is spring team first what is spring see now why spring framework has introduced into the market team what is spring for introduction we are going into city what is spring what is spring and why introduced into the market okay i don't want to give bookies uncertainty just for you know two days right gunshot answers like you know gunshot answers i should keep say team if i ask what is spring means i would say spring is and framework but why introduce this spring into the market the main goal of the spring framework is the main goal of spring framework is spring framework is to make j2ee application development was easier to make j2ee application development was easier team okay to make j2ee application development was easier we should go for this spring framework that means hey what are the drawbacks of this of the j2eoc applications look at drawbacks the drawbacks of this jta applications i don't want of each and every drawback i will give only a title stream j2e applications are tightly coupling applications t okay tightly coupling applications j2e applications are tied to couple applications means if you want to write first to what is mean by j to eet j to ee means i would say servulet jsp ejb rmi ejb all all will be comes under j to e so all j t applications are tightly coupling applications tightly coupling applications means if you want to write any one simple hello world circulate you should be extends your http in circulate are actually circulated interface implementation you should see strictly coupling tomorrow if you want to migrate from your circular any other technologies you cannot do you have to write so much of code you have to write team tightly coupling means now here your class should be extends with other class t means our applications okay our applications should extends servulet or ejb if you are using ejb ejb and so on whenever you are okay extending your servulets or ejb you have to override your unity methods service methods ejb predefined methods so that tomorrow if you want to migrate from your ejb to any other framework you can't do it next okay drawback is okay it's a heavy weight all jd yok applications are heavyweight team what is the concept of this okay it means no see if you want start your jd applications if any working guy is then they will be able to know in 2010 something minimum 15 minutes it would happen it will be so many classes so many you know so many framework delegated classes so many our app server classes it will take so much of time application startup will take more extra processing time team application process of application startup startup will take will take more extra will take more extra processing time t now next to drawback boilerplate code very very important what is boilerplate code t so common code is getting repeated in multiple places to do some activity is called a bilateral code for example jdb connection so it is a common code which is required for okay everywhere common code is getting repeated repeated in multiple places team to do some activity it is called by the plate code fourth one cross-cutting concerns that means if you want to implement any security transactions you know so in all the layers of your applications your j2ee does not support it it does not support j2ee does not support security transactions you know all connection pooling if you want all these things you need to implement a manually it does not support inbuilt need to implement manually see to overcome all these problems to overcome all these problems now here to overcome all these problems spring guys you know one of the guy from j2e team that guy name is rod johnson this guy team rod johnson this guy is also is a part of the j2e project this guy is also part of this jde project team what this guy did you know with all the drawbacks of this j2e application he was like disappointed okay he was disappointed he came out from you know sun micro systems he you know he he was build a one company and a team is called interface 21 is called interface 21 because of all these drawbacks because of all these drawbacks all these drawbacks of j2ee applications j2e applications there is a person called trot johnson person is called rod johnson okay the guy has okay the guy has okay started a framework is called starting of interface 21 team he is from sun micro system actually he is from sun micro system he came out from occasion micro systems and he introduced a one framework is called okay introduce day one framework is called spring team okay introduce today one framework is called spring team now let's see got a team any questions you can ask so i would say spring has overcome all these problems team obviously so he is from person is called rod johnson okay now he is from he is from sun micro system his terms and micro system and he was he was okay disappointed he was disappointed but disappointed with his j2ee futures with j2ee features okay and started started something was called interface 21 interface 21 intra phase 21 renamed was was renamed was renamed as spring springtime okay now what are the advantages of this spring spring advantages there are so many advantages are there in spring what are the drawbacks of all your j2e applications no spring spring can you know overcome all this one first one is spring application make application development as easier make application development development easier team how the easier and all means now we'll see spring provides a future switch to all the all the enterprise applications which helps okay involving a development team and also spring applications are lightweight what is lightweight the startup time it will take very less steam okay it won't take any too much time here spring has modularity team what is modularity now here spring has provided around 20 models a team spring has provided around 20 modules these days now spring core spring mvc spring batch spring transactions spring security so many team and also one of them is called spring boat spring webb okay webb mvc springer diego spring aop okay so many understand spring has introduced around 20 modules team now see to develop only standalone applications use core to develop web applications use mvc to develop batch applications use this batch to develop a security use the security that's why you know spring is another advantage is it is bozo based development team why pose a bishop development spring does not force to your application implement or extending any spring framework classes spring does not force your applications sprinkle does not force spring does not force your application does not force your application to extend or implement to extend or implement any spring framework classes any spring framework class st see how much advantage is there with the spring tomorrow if you want to migrate from spring to any other framework happily you can go ahead team happily you can go ahead to team spring is more popular because because all spring applications are loosely in coupled applications loosening coupled application and unit test code and unit test code okay these are the advantages in string but the question is see any framework team i have seen in my experience from 2008 to till now 2008 to till now i was working on starts i was working on wicket i was working on jsf now i have been working on spring but why spring spring is you know sustained sustaining in market means good thing is team please any framework is available in the market spring what this spring team is there spring is ready to provided you know one model for that if you want what this spring will do hey you don't need to write too much of bilateral code spring will give you a one with the latest version they will give some utility classes okay spring radius it will be supported if you want to work with in the market mongodb you don't need to worry mongodb okay yes spring spring has provided a predefined uh apa is called template of something no way i'm telling anything in the market there is a cup car no problem spring has provided a one three different classes is called kafka if any technology is available in the market which is the famous spring on spring has provided you know apas to communicate with that you know okay technologies that's why everyone is you know preferred for spring spring is crazy kafka don't write a you know code if you're writing code you will write 100 lines code i will provide i mean i'm i'm i mean spring will provide kafka template so kafka template will write internally all this code how to connect to this kafka and all developer no need to write too much of code jms everything team security everything that's why spring is more popular in the market team understood team now our concept is one of the famous module in spring code spring core is the module without the spring core no project stream without this spring core no projects are there in the spring so even though you have so many models are there even though you have so many models are there but underlying modules spring core team spring core is the base module of entire spring framework spring core is the base module of entire spring framework so if you know this spring core you can play the games like with the aop davo or any new model also will be coming to you that's why it is a base however building base right if base is not strong what happen building will be collapse similarly in this entire this spring whole this spring project hold this spring framework spring core is the base team if you know this spring core now you can understand other models will be easy team that's why see how this it is this image has given by the spring team okay so that's why we are going to learn in spring corn now team okay spring core is very very important now here what this spring core will do okay or this okay spring core will do is our next question team what this spring core will do before start our spring core before start the spring core first one is first one is we need to start why we should go for this spring core i why we we should go for sprinkle i would tell look at definitions easily but the next one in our in our project development team in our project development he'll write one one statement spring core is the base module for all all of the other module for all of the other model t other model okay now so why i should learn this pringle core sprinkle in our project development in our project development here only you you need some core java skills in our project development so how your project development is there now we'll see let us assume that i am going to write one class public class account account what information is there account every class will have a state every class will have a behavior every class will have a state every class will have a behavior i would say this state is called instance variable this behavior is called methods are functions state is called instance variable behavior is called methods and functions so what is this you know in our in our real time project wherever you are developing your project one thing is a mandatory means a class you are developing a class you are developing a class that class should follow the srp you have a concept is called solid principles that will discuss later letter means not this two days in solid principle yes means srp okay means srp srp stands for single locker responsibility principles srp stands for single responsibility principles that means whenever you are writing any project to code that classroom should have only one responsible to modify to touch a class should not have two things a class would not have user's information a class should not have customer details this is wrong you are developing any project the third project should have only one responsibility a class means either you should give either you should give only user details or you should give customer details either you should give only user details or you should give customer details you should not combined both into single it is the one of the mandatory solid principles whenever you start this solid principles okay srp stance singular responsibilities means means every every class every class should have one responsibility every class should have one responsibility it is a very very important in our interviews what introverts are asking can we explain about solid principles what is what is lid we'll discuss in upcoming class later but as of now every class should have only one responsibility it is called single responsibilities don't don't include your users details and account details a class should have either user details or you should have account details okay now during you because of these solid principles during your project development during your project development we would have multiple classes every project every project every project would have multiple multiple classes okay every project would have multiple classes if multiple classes okay very classy okay if we follow if you follow srp okay srp means single responsibility principle single responsibility principle now next one for every class you should create object developer has the responsible to create the object every class developer should create the object every class developer should create the object an application is running an application is running these objects should interact with another object when application is running these objects should be interact with another object another objective okay when your application is running these objects should be interact with another objective small example small example now here see simple example our a class a class a here i have a class b i have a class b now here c class a and class b class a is now here depending on class b i need some amount okay amount is available here class a usually depending on class b to get the some amount now what i should use bb okay now i should call in this here i have a some method now here what should i do so no need all this data for this stage my class a is okay depending on class b class a is okay depending on class b i would say i would say my a class is my a class is dependent class a class is dependent dependent or source class people are calling a dependent or source class my b class is b class is dependency class dependency class are target class please try to understand basics are important okay dependency class are target class now here see depends here okay my a class is depending on this one now here see all spring core is nothing but spring core is nothing but spring core is nothing but how to maintain the dependencies sprinkle it is used to manage the manage the objects dependencies how to manage the objective dependencies now we'll see practically we'll see how to manage the object okay dependencies practically we'll see now so here is okay clear right what is mean by dependency what is mean by dependent and what is mean by dependency you dependent dependent dependent is usually two dependent is you zero two so always in our project right in our in our project okay big big classes are there compulsory one pro one class should communicate with another class dependent means it is an it is an object object which is required which is depending on which is depending on please try to understand which is depending on depending on another object okay depending on another object depending on another object another object to get some information what is the dependency what is the dependency okay what is the dependency dependency is used it is an object it is an object required by required by another object required by another object to carry out to carry out the functionality please try to understand i told already basics are very very important you may get to pour but please have some patience to understand all this stuff in your in your project development compulsory you would be there are multiple classes are there in in our project development in our real time so compulsory one class will be depending on another class here i have a class c i have a class b class a is okay depending on class b class a work depending on class b here class a is called a dependent and the class b is called dependency and the class b is called a dependency okay right now here see so now you came to know what is dependent and what is a dependency now actual game will start now please try to understand i will be providing all this to other end of the class now i will take one small hour our real our real use case team that is our real use case simple example common example do you know what is mean by this pedigree i have a three object stream pedigree object dog object dog owner object i have in three objects and three objects are very simple objects you can so why i am explaining this means we can understand in our uh you know understand in our day-to-day real-time activities pedigree dog object dog owner object these are the three classes team how this simple class you know public class pedigree what is the they're here simple method public wide editing okay done here simple class why am copy paste means these classes i will be used for in another approaches another approaches so they will be used for this classes team now next one see now please try to understand what is the class here how the class is then public class simple class you have a dog what is the pedigree means dog food routine however we will be eat our breakfast our dinner right it's kind of dog food is called pedigree public i am writing one constructor constructor is called a dog here i am creating object this dot p is equal to new pedigree new pedigree now please try to understand now public y et method here you will be calling this dot p dot e to t now done now done so now this is what one simple class team one simple class here my class is a candidate i am saving this class also why i would be using all these classes in upcoming approaches okay instead of typing again go to here team what is my simple dog banner class public class dog owner assume that we have your code static wide method and all i'm i don't want all now what happened here dog d is equal mu dot newton dot d is equal to nu dot t okay let's assume that here we have one simple okay so p is there system dot out dot intellect yet some pedigree eat pedigree eat pedigree now let's see what is the output team see my dog owner is okay depending on dog my dog is calling to my dog owner will call to this dog dog owner will call to this dog so dog owner has the responsible to create the object of the pedigree and my pedigree you know my dog will call to eat method can anyone explain what is the output team now here what is the output team here now what is the output team can we say output is it pedigree or not team hope you are following yeah now here here actual game start team now here see please concentrate please concentrate good now here see my dog owner is depending on is depending on dog my dog is depending on pedigree i would say this is called dependent our source or source object some people are calling dependent some people are calling source object here this will be acting as a dependent under dependency dependent under dependency but this pedigree would be acting as dependency or target object can anyone explain what are the drawbacks with this approach anyone in this approach what are the drawbacks in this approach drawbacks or disadvantages or advantages will talk disadvantages and advantages disadvantages yeah and okay advantage is good someone is a corresponding advantages see first disadvantage here you know please try to understand first two disadvantages here here this dog right dog right advantages superwork advantages is your dependent does not know internal details of the dependencies means your strong encapsulation here advantages is strong encapsulation team why strong encapsulation what is your encapsulation that's why hoops concepts are pre-requesting here we have strong encapsulation we have participant encapsulation let me explain here we have proper encapsulation in our place proper encapsulation in place encapsulation is maintained what is encapsulation here encapsulation means hiding okay work implementation details are hiding encapsulation is nothing but data hiding place abstraction here dog owner don't know what dog is eating dog owner don't know internal details of the dog dog owner just to create the object of the dog dog will take care to you know send the pedigree food to your pedigree class that's why here advantage is proper in encapsulation is maintained because of because dependence dependence may be dogger dog owner or dog doesn't know doesn't know the doesn't know the internal internal details of their dependencies internal details of the dependency what is a disadvantages t now first to disadvantages is tightly coupled what is tightly coupled here dog only eat pedigree only if you want to supply other than the pedigree like chicken or mutton or whatever it break or whatever it you should go to dark class you should modify the code manually if day after tomorrow it will eat another one you should modify your code manually that's why it is dog eats only pedigree that's why it is called titling couple routine if you want any new food you should change your source code if you want a new food you should change your source for team second one team we can't write the unit test cases the code is like this we can't write the unit test cases there is a difference is there unit testing and rock integration testing these days market without unit testing there is no project in java that's why maven software has written maven software has provided one src test test folder every every project unit test cases are mandatory without unit test cases there is no project to implementation t but here we are actually we are missing this unit testing team here we are missing here you need to get testing team here so now what happened to overcome these problems now what happened to overcome these problems now slightly we should change team so drawback one is it is tightly coupled and uh you know uh and also we can't write the unit testing key advantages is super proper encapsulation is maintained because of dependence don't know the internal details of their dependent system to overcome these problems how our structure would change team to overcome these problems however our coding structure we can modify our coding like this how to do simple team that's why i'm copy paste earlier my code i'm using here this simple one i'm not complex but i am not copying all these simple only it is my pedigree it is my dog dog now what happened here you know instead of you will created the object inside of your constructor now you will created this object here inside constructor means it is not in our hand this dot b is equal to p it is now your num p dot it that's fine now that's fine so now you have a dagger public class dog owner i don't want to write too much of code i want to write some pedigree p is equal to new pedigree dog d is equal to mu dot okay now here i should pass here p is it loosely coupled for some extent but still it is tightly coupled only pedigree only always you shouldn't supply the pedigree in this approach what is the drawbacks you know first drawbacks still it is tightly coupled second drawback encapsulation is breaking here why encapsulation is breaking your dependent knows implementation of your dog means your dog will eat only pedigree only to overcome this approach if you want to communicate with if if we want communicate with in project development in in project development there would be multiple classes if we want to communicate with the one if you if you want to communicate on object with another object then we should we should we should communicate via interface not direct classes let's see what is the interface approach t what is the interface approach see here what is the interface approach here we have a space we'll see here interface approach see what is the interface approaches please concentrate i will use it okay interface is called public i will use interface is called public interface food is the interface what is there here public wide it by default interface will have public only you no need to specified any wired how many classes we have so many implementations so many implementations we have class pretty great implements food okay now another one is here we have a ampere one is interface another one is impl so many implementation classes here it is pedigree done another one is if you want to eat bread another one is if you want to eat meat all it is an interface it is an interface team now please try to understand now how my dark class structure know very simple how your dark classical structure is there see here how your dark classical structure is their approach three it is what i will do here i would pass here four to t [Music] this dot f is equal to f heat and all okay now what happened the flow will go to any of the if you go for what food you are going into provide now let's see now we have a class is called dog owner now please here there is a now it is what food you want to know you want food is called bread or you want a food is called meat or what food do you want what food do you want you want to braid or you want to eat or what food do you want no you have to provide that one team you create the dog object new dog pass that food here this is called loosely coupled routine this is called loosely coupled but here what you are doing here manually applying your dependencies here this is called loosely coupling now it is called 100 percent it is losing coupled thing it is losing coupled far so under and also it is a unit testable code what are the advantages with this is please try to understand now we are entering into our our spring core if you understand this we are entering into our screen core first advantage time it is unit it is losing coupling why it is losing coupling whatever you want to put you can at run time you can pass that photo without modifying your dark object you can you can you know send a pedigree you can give bread or you can give me two whatever you want okay you can give them for duty conduct your team next one is unit test to kodi it is unit test code unit of testable code means the drawback also here team first drawback it breaks the encapsulation why your dog owner should know what dog will eat that means your dependence knows the dependencies implementations second one is unnecessary it creates it creates unnecessary objects it creates unnecessary dependencies between it creates unnecessary dependencies between between unrelated unrelated classes are objective objects objects objects so to overcome all these problems to overcome all these problems there is a concept is called dependency injection what that concept is there here you know ccc here to overcome all these problems please here only problem to overcome these problems we should go for a dependency injection what this dependency injection will do public class it is dog owner only but i have a constructor is called a dog dog what i will do private dog owner you should see here dark dark theme please try to understand this dot dog is equal to dark that's it that's it advantage one here dog is losing coupled food advantage to you can write united advantage in three no broken encapsulation why your dog owner don't know what dog is eating food just your dog owner will pass the dog object no here the question is who will supply the dog object who will supply them for the object who will supply the dogma object that is called dependency injection what is the advantage here please in this approach team advantages advantages means first advantage dog is loosely coupled second advantage is here unit test code you need testable code thought advantage here third advantage here no broken encapsulations encapsulation unnecessary dependencies between the classes and objects no need that is that is no need internal details of details of dependencies dependencies it understood so if you look at code if you look at this core team this core team if you look at this code this code if you look at this code only this code please this code if you look at in this code is there anywhere a developer is creating object steam are you seeing anywhere a developer is creating the objects are you seeing anywhere a developer is creating anywhere objects no developer is not creating the objects anywhere developer is not creating the object anywhere if you look at this code developer is not created object anywhere but developer is expecting someone will create the object so developers are expecting someone else to be created the object that is someone else is called spring spring will provide this object to team someone is called spring spring will created the objects team spring will be created the object hundred percent it is loosely coupled unit testable code encapsulation also it should not break understood how this spring will provide these objects now we'll see now in spring core or the spring core okay spring core okay using these modules using this modules okay we can using this models spring will create the required objects required objects required objects and supply to application supply to the application that is that is developer developer no need to create no need to create any objects in no need to create any object in application development application development so that so that our application development is our application would be loosely coupled application would be closely coupled now here see how spring will supply this one how question is how spring will provide the objects how will spring will provide the objects how to get the how to get the objects from spring now it's important to implement to implement spring ioc to implement spring core we should we should follow three step step step one configuration step two step two dependency injector i will explain in depth to team housing jvm would be happen okay everything will see now step three step one how to configure and step two dependency injector step three get bean use the beans use the beans use the beans are get the beans use the beans are get the beans step one configuration step 2 dependency injector step 3 use beans are get the beans get the beans and use them and use wherever required very very important team please concentrate please concentrate i'm going to draw one diagram if you understand this diagram it is very very easy first one thing configuration stream configuration you can do oh you know you can do either xml or you can do either java config and all okay in spring first 20 configuration team i would explain how these beans will be created jvm and all i will explain everything please try to understand here the step one is step one is configuration we'll start from here step one is configuration t this configuration is maybe xml configuration maybe java configuration here you would be using xml or you would be using java configuration if all radio xml is there why you should go for java configuration if already java configuration is there why you should go for annotations all will discuss team all we'll discuss next one is xml configuration java configuration and the next one is annotation setting now always configure three questions team number one what objects to create number two how to create them number three what dependencies inject inject please try to understand what dependence is inject what dependencies inject no this three are important so first to an answer what objects to create what objects to create you need to create objects first one answer means you need to create dog owner object you need to create dog object you need to create a degree object you need to create dog warner underdog dog warner dark pedigree bread meat karma food all these objects are created okay what objects to be created means you should have clarity these objects we should bring create now here see how to create how to create and what dependencies are required that's all you should know team that means you should do first one how to create c create pedigree object second one pedigree object will always how the object will be created default constructor only object would be created using default constructor second one create dog object and inject inject into pedigree object inject into pedigree object third one create dog owner object and inject inject dog object inject dog object inject dog object injector dog object injector dog object which is created created in step two which is created in step two please concentrate first two you know what happened step one it is a one comment step two it is a one comment step three it is a one comment how your spring understand all these comments spring understand one language is called that language is called some configuration beans understand one configuration i will explain to him in depth we will see beans here we are going with a step by step beans what this spring will do okay first what object you want pedigree object no problem b id is equal pedigree class is equal com dot sri no tech dot pedigree please try to understand next to half an hour very very important how this will be loaded into your jvm and all we are trying to see next half an hour please okay try to understand okay next half an hour now see okay now created the dog object how to create this dog object here same like being id id id no dog object means dog class is equal calm dot c note equal dot dot object but dog object is required for what dog object is required for what dog object is required pedigree how to require if you see our source code dog object is required pedigree via constructor oh yeah constructor t i would pass here constructor you can see reference is equaled pedigree please try to understand pedigree okay now my dog what is the last step last tip is called dog owner dog owner instead of typing team i'm copy paste here dog owner com.strenotech dog owner constructor argument here t these kind of instructions you are going into provide these kind of instructions you are going to provide this is the configuration configuration does not create any object configuration does not create any uh you know objects and it will not load anything configuration is you just provided an xml or annotations later we'll see at this stage of xml how your spring understand how your spring understand this xml you have to provide this configuration you have to provide this configurations team so that let's assume that you will give this configuration is nothing but uh you know spring or spring config dot xml xml okay how to config how to all will see practicality see you are injecting you are trying to injecting your dab object via constructor that's why it is called constructor injection so dependency injection means the process of getting the dependencies the process of getting the objects instead of you will created the object someone else will provide the object that someone else is called spring will provide the objects that is called dependency injection so here you are system providing your instructions here that is called configurations team that is called configurations just you provide the instructions what you want of how you want that's it any questions here no now actual game will start now so what happened you know this configuration will be given to whom you know this configuration will be given to your dependency injector these configurations will be given to whom dependency injector this configuration will be given to whom dependency injector dependency in injector very very important c dependency injector now how you will be supply this dependency detector you know i will explain later team all i will explain later there is some class is called bean factory new there is a class is called bean factory routine been see whenever this bean factory would be executed what happened i will explain new xml bin factory you will be provided new class path new class path new class path resource or new class path source whatever new class path resource you would pass your xml file what xml file spring if unconfigured for an xml file please try to understand so you are supplying your configuration configuration means just to configure what you want how you want whenever you are supplying your xml to your injector what this injector will do what this injector will do it will what this injector will do it will read it will parse your xml if your xml is okay and everything is good okay it will reach all the configuration and understand it will read all the configuration understand what what to do okay and you know it will create a one container it will create a one container i would say that container is called spring ioc that container is called spring ioc i will talk about more on this container this container is called means spring ioc spring ioc here it is called container what is meaning container container means something information in our we have some containers right so what this dependency inductor will do will parse or read configuration and understand understand what to do it will it will it will create a one container inside of the container first two per degree object will be created next dog object will be created next dog owner object will be created first pedigree object will be created next dog object will be created next dog owner object would be created now here how the internal it will be happen that let me explain spring container spring container holds all the objects all the objects okay references all the objects of the references created by dependency injector all the objects okay references created by dependency injector now next one if we want object if you want to object it from container if you want object it frame container okay instead of create okay instead of create the okay if you want object okay if you want object get it from container get it from container okay instead of create okay instead of create manually manually while creating these objects what happened you know automatically this dependency injection also would be happened automatically dependency injection also it would be happened how how the internally will be working sir how the internally will be working very very important now where the jvm will will come here here the jbm will come here the question is now what happens when you create the bean factory what happened when you create the bean factory please try to understand what happens when we create bean factory or execute okay what happened and we create the bean factory object so what is our bin factory code bin factory factory is equal new xml bin factory our new class path whatever it new class path resource here xml file and now what this statement it would be executed what happened you know please try to understand first one first one it will it will read the it will read the xml file it will read the xml file and validate it will read the xml file validate it if the xml is valid it's okay if the xml is valid then if the xml is valid then then it creates it creates xml then xml bean factory xml bin factory creates creates in memory in memory logical memory in jvm in memory in memory in partitioned in memory logical creates in memory logical memory and partition inside jvm inside jvm inside jvm next one so loads loads loads this spring beam configuration file and replace metadata metadata means all these are called metadata all are called metadata and place metadata in the logical memory just try to understand so how whenever you you are loading your xml file your xml bin factory will load a whole okay it will create some memory inside of your jvm it will load whole xml into so it will place place means your metal data means all your pins information in the logical memory partition you know the logical memory partitioned participant logical memory partition created by xml bean factory is called ioc container is called ioc container is called ioc container and it returns and it returns the reference reference of ioc and it returns the reference of ioc ioc condition returns the reference of ioc container as bean factory means simple team the okay it returns the reference of high washing container as bean factory that means it will give as a reference is bean factory bean factory around or of application context okay i will explain factory r application context team and you call now step two is done step three how to get the object and you call bean factory dot get a bin i want a dog owner object i want a dog water object i want a dog one object see whenever you called this one now what happened you know it goes to first in memory in memory of the eye washing container it will search if the bean is present inside of the container if it is find if it is not fine it will throw error is like exception and terminate your application if not find if not find no see step number one so in this case your bean factory goes to goes to ioc container the bracket logical memory under searching searching for the bean definition searching for the bean with given id right image dog owner dog owner if the brain definition is not found if the dog warner is not formed then it will close exception an exit application once the beam definition found once the bin definition found then it will read it will read the corresponding class name it will read the corresponding class name it will read the corresponding class name and loads the loads the class into jvm jvm memory and instantiate instantiate instantiate the object of the class instantiate the object of the class to start understanding instantiate the object of the class understood do you think i was in containerization software no it's not a software it's a just one logical memory partition one logical memory partition so whenever the statement will be executed it will load the whole xml file it will created the one logical memory inside of the jvm it will load all the metadata means all the configuration inside in this xml file so the logical memory partition is created by the xml factory is called ios in container and it returns the reference of ios in container as a bean factory once you got the reference of this bean factory bean factory dot you can perform any operations with this container okay once this bean definition found then it will read the corresponding class name and loads the class into jvm and okay on the an instantiate of the classes okay okay book instantiate the object of that classes understood any questions team here any questions here what is mean by ios in principle ioc means collaboration ioc means collaborations collaboration of objects and managing managing the life cycle objects is called ioc what is mean by collaboration collaboration of objects what is mean by this collaboration collaboration means managing dependencies life cycle means then object will be instantiation and an object will be destruction understood right ioc is there collaboration of the objects collaboration of the of the objects means main is the dependencies of the objects and managing the life cycle objects is called ioc is called ioc questions team any questions now connect one team see whenever this statement would be executed to implement spring ioc always we need in three steps are required to implement spring io always we need in three steps are required first step is how to configure second step is how to apply this dependency injector first step is how to get the beans of already created beans all the beans team look understood team so here here dependency injection two ways you can do this how to manage the dependencies manage the dependencies in two ways one is dependency lookup so dependency lookup means if we write the code to manually go to the container get the object is called dependency lookup if the developer developer write the code write the code to manually manually go to container and get the object get the object is called dependency lookup number two dependency injection dependency injection means it will it will provides the automatically it will provides the objects dependency injection means automatically automatically get the dependencies objects how it happens now we'll see practically understood not always your spring container will store the objects only object or references only under but objects will be stored in jvm objects will be stored in jvm jvm understood so whenever this statement it will be executed what happened here all the objects all the objects would be created here your references would be inside of this container objects would be available here your jvm so here what are the objects here you will get pedigree object you will get it dog object you will get it dog owner object that's all team now here see now what happened here so now till now we are clear now okay everyone is asking is container is software or hardware answer is no it's not software it's not hardware container is just like a hash map hash map hash map what are the hash map here hash map means key value where key is equal to id and value is equal to class name key is equal to been id and the value is equal to class name g bean is equal to where key is equal to b id and the value is the class name thing spring internally will use you'll use reflections to create the objects inside jvm to create the objects inside the jvm understood dependency injector means so instead of you will do if the dependencies are required for an object external component you will supply this object is called a dependency injection dependency lookup means developer has the responsible to go to the container and get the required object understood team any questions here any questions here you can ask most of them people are asking sir what is the difference between dependency injection under ioc answer is no nothing dependencies so you would tell to answer inversion of controller ioc io means inversion off controller what is mean by inversion inversion means i have a class a class a is okay depending on the class b class b depending on class c this is called inversion if if a class will have multiple dependencies then if a class will have multiple dependencies then it is inversion it is called ok version so inversion means if you get the a a automatically will bring the b b automatically will bring the a if the class will have a multiple dependencies then get all the dependencies get all the dependencies through one class is called a okay inversion so is it inversion of the control under dependencies both are in same means answer yes yes see dependency injection is though one type of the inversion of controller on type of inversion of controller it does not mean that dependency injection is the only type of inversion of controller to achieve this inversion of controller so many are there one of the pattern is called dependency injection answer what you will tell your interviewer dependency injection is the is the one is the one type is the one type of inversion of control one type of conversion of control it does not mean that dependency injection is the only of one type of inversion of controller so there are so many flavors are there to achieve this inversion of control so dependency injection is though of one of the flavor one of the type to implement you know this ioc understood team any questions team till now you can ask any questions tim till now you can ask him any questions streamed in now see if this is this example all the objects who will create a team all the objects we will create [Music] yes yes concurrent dash map also would be used see with this diagram so you just just configure all the objects configure all the objects yeah good question this okay xml bean factory also will be created inside of the jvm only but the reference would be created reference would be created object is inside of the jvm the reference alias name is referring to your container xml beam factory everything inside of the jvm only it will created the one logical partition means the objects are there here only but reference would be given to your container code in our application only i will show you sir after some time i will show you so source code is no you should write code in our application only code is not like uh you know code is not like jbm are you following sir sir please tell me now i see been in application config but don't know where to put certain that i will explain sir that i will explain give me time in practicals you will be able to know all just a given uh you know okay xml is there bean factory is there i would explain okay in depth in our practical stuff in our regular practice i will explain maybe after break we will start our examples only so okay at this stage before you break where you would explain means in our java class you'll write sir public class application inside of the application you would write create xml bin factory next one okay each will load which will load config which will load xml file here now what he will do bean factory dot get been off dog owner okay yeah i will explain sir in in in practical okay you will be able to knock everything sir give me time okay it is only fun just talk introduction i am explaining here now you will use in your code wherever you want to dog object okay dog owner object you can use it sir i will show you practically it is available in public static wired me just for giving a rough code it is cut off qualities okay sir is it clear now here see no so till now what we have discussed okay questions team till now please ask till now what we have a discussion team drawbacks of j2ee spring advantages team spring advantages team next one team we have a discussion about what is dependency injection so ioc there are many types are there i was your inversion of controller okay i would explain some there are same dependency injection is the one there are many ioc are there dependency injection is not on u1 dependency injection is not the new answer another one is called juice juice is the google framework juice is the google framework it is included by google it also uses the dependency injection ioc is though one of the flavor of this dependency injection sir okay i would explain in after this so in during programs okay i will explain sir okay yeah see now till now we have discussed about only basics only basics what is the introduction what is dependency injections and how many types is there in in practical i will explain sir now he'll start oh look xml i have shown but after the break right we will start our 25 examples practical lister okay 25 examples practically how many types of containers types of spring container we have only two we have only two one is bean factory other one is application context i will show you practically if already bean factory is there why you should go for application context i will explain practically sir so from after the break he'll go for only practicals only practicals if already xml is there why we should go for java config what are the drawbacks with this xml okay what are the annotations we should use everything we'll see after the break all okay interesting topics would be there sir okay please don't miss okay after the break what is mean by dependency injection dependency induction means it is the process of okay it is the it is the process of getting getting the objects getting the objects from spring container instead of instead of created by instead of created by the developers instead of created by the developers instead of created by the developers it is the process of it is the process of getting the objects from spring container instead of okay instead of created by the developers okay now here teaching okay very very important now in this concepts now what happened how many ways you can apply this to the dependency injection one is shutter injection another one is constructor injection one is saturn injection another one is constructive injection another one is constructor injection so what is mean base in shutter injection what is mean by constructor injection when you should go for a sector injection when you should go for constructor interjection team now here see please try to understand i have class a simple okay i will give them later i will explain in our examples and i have class b so you will be informed to your spring hey spring i am depending on class b how you are depending on bb that's fine so you are depending on your b where constructor you are depending on b y constructor this dot b is equal to b this dot b is equal to b here we have nothing is there as of now ignore it here we have simple class is called b class what is there how is there we will see you are creating your object via constructor it is called constructor dependency injection if it is shutter means team ultimately who will give this who will give this in your spring xml only spring if one config xml instead of you will be struggled okay instead of you will be struggled who will give your spring only will give how this spring only will give beans bean just i am telling here be in id id b class is equal b class com dot is t dot b class i would explain to him all this but how to do your officer injections a transaction means i have a b is there how to implement this or centric deduction means class a i am injecting via setter thing b b you need to write sector here how to write setup public wide set a sorry set b now here you should write it here b b here b b b please be on mute this dot b b now done actual interested thing is now here see what is mean by dependency injection so when you should go for how this can be a helpful team now here see now please try to understand how it is happened and done very very important thing when we should go for shuttering injection and when we should go for constructor in the rejection i will show you practically before the going to practically i will give up one smaller definition t so that you will be able to know i am using setter injection okay extra injection conference will now be recorded okay next one injection the dependent object is injected into targeted object via constructor is called constructor injection he is called constructor in injection team is called a constructor injection okay now we'll now we'll see now we'll see so when you should go for this i would explain now practically we'll see so it is first example t i am going to see constructor example t see you can take either one of the example what is the use case of this example t use case you can take customer customer will use some credit card credit customer will use some card this card will go to some payment this is the use case are sorry easily understand use case everyone it is okay but everyone means simple team simple i want i want use some use some i want to use some and i want to use ink ink required some pen using when i will write something just a simple use case ink pen and write a simple use case at the end of the course i will take in this use case also and i would explain to you what is the use case analog i would explain at this stage i am using this one thing simple one means my pen is ink is depending on pen and pen is here no my pen is okay depending on ink okay now how to write here so using pen i will write something my writer is depending on pen it is a writer my pen is okay depending on the ink team okay it is a simple use case so many okay examples we are going to run in this team so many examples simple examples public class writer what is required here writer trend is required simple use case i am taking pen is required now how to use this constructor constructor constructor important constructor i'm injecting this but who will supply the objects spring will supply how this spring will supply i would explain here your writer your writer is depending on pen [Music] pen is depending on ink ink how to inject this ink wire constructor so you are not going to create any object in your application who will created the object who will supply the objects your spring will supply the objects doesn't matter if it is a web application any module web application batch jobs spring boot dao mvc orm any module all the models objects are required right who will give objects all the modules our spring core model will how the spring core model will give it to the help of dependency injection how the dependency injection will work now that much of power this spring core okay now here see okay important here now here some methods are there okay now we'll see so you are not creating any objects here no first example i am going with xml what is xml team hope everyone knows this maven maven means it just to provide the your spring dependent system so to develop this i need spring core jar is required and i need spring context jar is required i need spring core jar is required i need spring context which are is required okay now here's the next one this this dependence i will use in all the applications i'll take examples first example we are adding the circuit dependencies okay next one ct next one i have one writer my writer is okay depending on my writer is okay depending on pen okay pen is the interface i told if you want to communicate from one class to one another class always always interface is required always interface is required now i have an interface now i have an interface now please try to understand i have an interface now interface what is the implementation pane implements 10 it is dependence on what ink go for ink ink implementation is as of now black as of now blocking team i have two interfaces pen implementation is fountain pen ink implementation is black ink writer my writer is depending on pen my pen is okay depending on my pen is okay depending on ink any have you seen anywhere developer is creating object steam have you seen okay anywhere developers are creating objects have you seen anywhere developers are creating the objects to communicate from writer to from writer to pen and pen to ink no right good now here see now please concentrate who will create a configuration team configuration configuration city this is common what is the use of this means to validate your xml document is valid or not that means bin will have how many attributes you can't write in this bin abc xy that it will give error to validate this whole xml is valid or not using this namespace system using this schema that's why it is mandatory now first starts from there to writer writer is depending on fountain pen pen is depending on constructor argument black ink are you clear this configuration or any doubts this configuration are you clear or not just i have provided the configuration in xml configuration bin id is equal to writer bin id is equal to fountain pen binary is equal to blocking okay everyone please okay respond are you clear or not everyone okay hope you're clear team now so all are good with this configuration now how to load this configuration how to load this configuration so that so that how to load the configuration to load the configuration i need what i need what either xml bin factory or application context application context is required you should go for being factory or you should go for application context i will explain when you should go for being factory and you should go for application context now see that's why we should go for see application context context is equal new class path xml application context application context context is called new class path application context whenever the statement would be executed say bean factory is on one interface bean factory is on one interface there are the implementation classes is one extend interface is called application context under this application context so many implementations classes are there so many implementations are there depends upon the requirement you should go for and i should go for bean factory and i should go for application context i will explain bean factory is an interface you have two things extend another interfaces it is one is implements another one is extends one is implements another one is extends implements a class is called xml bean factory implements a class is called xml bean factory extensor class is called application context that means application context will have more features than bean factory bean factory when we should go for bean factory and you should go for a application here which implements application context implements application context interface implements so many classes if you are using okay xml configurations implementation class is called class path xml class path xml application context if you are using java config annotation config application context so many implementations if you are using only file file system xml application context so many are there so when you should go for bean factory when you should go for application context bean factory is only suitable for standalone applications standalone applications it is only applicable for standalone applications standalone applications for dependency injection application context not only for standalone application context will be helpful for standalone applications and also web applications web applications and also it would support for internalization i 180 application high internalization application and also it would support for during startup if you want any events application event it supports for aop it supports for application events everything it would support for all it would support for all standalone applications a bubble license okay i 118 applications aop application application events so now because it is at the extents of your bean pepperoni bean factory will have only standalone applications for dependency injection whereas application context would be in support for all if your configuration if your bin configuration available inside of xml go for new application new class path okay xml if your bin configuration is available in java config now go for annotation config application context understand sir depends upon the requirement you should use all so here i am using application context context is equal new class path xml application context whenever line number 12 will be executed your application context will be created a1 logical memory inside of your jvm inside of your jvm and it will load all the metal data of your xml document and it will load all the material data of your xml document and stores into memory stores into memory understood sir and it will create stores into memory and it will creates is the application context okay reference here application context reference here that means and never line number 12 will be executed line number 12 will be executed now here what happened you know during your application startup it will take your creation of the partition objects all into your memory so it will created the it will create the ink object it will create the pen object it will created the you know writer object here ink object pen object and writer object here your writer would be injected to pen your pen will be injected to ink writer will be injected to pen pen will be injected into writer it is called your application context your application context object is the reference is the reference application context object would be reference here application context object would be in reference here team please try to understand so whenever you called this a context dot get to writer okay never you called context to dot and get been there are so many overloaded methods are available in get bin what are the overloaded methods context to dot context to dot get been off context to dot uncertainty run as mvid installed spring tool should only write i have independency all dependencies are available here we have an update project context dot could be enough now context to dot context dot get pin see get bin you will have so many overloaded methods team will have so many overloaded methods here get bean get bin string name get bean class name get be in class name of arguments get bin string name class name so many there are four overloaded methods are available for overloaded methods are available team okay get bin means fire overloaded methods are there see whenever this statement would be executed whenever this statement would be executed what happened you know it will it will you know store all this it will create a one logical memory inside of the jvm it will store all the metadata it will store all the metal data of the our configuration it will store all the metadata of our configuration after storing all metal data about this configuration now now what happened you know and never you are trying to call context to dot get to be in what happened you know so it will goes to your container writer before creating writer object fountain pen object will be created before creating fountain pen object black ink object would be created all the objects would be created in where inside of your jvm references would be created in container inside of your jvm it will created a pen object will created it will created a writer object it will create a pen object it will created a ink object understood team it will create a writer object and pen object and link up and ink object to team so whenever you call this writer remember before creating writer object first pen object would be created before creating pen object ink object would be creating so when we okay executed this writer and we executed in this writer here writer here what happened here you know writer is creating pen object from pen dot and this right two okay pen is okay depending on what pin is depending on inc it is also calling see into here no no see okay here from this ink now from this pen it will go to where that's it here what methods are there what is the ink color ink brand name go to here inc color ink brand name that's it see if you run your application run as java application writing with the black ink of parker brand writing with the black ink of parker brandt any questions team please try to understand again please try to understand again writing with black ink off parker brand means see whenever this statement would be executed your container will be created inside of the container all your objects and their dependencies also would be available the dependence also would be available so these objects would been created inside of your jvm references would be inside of your container whenever you called getbind.writer of id with this id name only id means all your binocular references class means your objects class means your objects you are calling this object reference get bin of id you are calling with object okay reference whenever the statement it will be executed it will verify if this reference name is available in your container or not if it is available it will try to create the object if it is available it will try to create the object but before creating the object it will create the this dependent okay dependency object that dependency object is called a pen object but before creating the paper object it will created a dependency object is called ink object so first it would created the ink object and added the it will injecting into pen again it will located the pen object it will be injecting into brighter object automatically it came see is it clear or not first example have you created anywhere new operator first example are you clear or not first example everyone team please ask me if you understand this okay remaining will be easy if it is a difficult okay remaining will be difficult i want a correspondence everyone please first example clear team yeah good yeah sure okay okay i will repeat once see it is my project development team just for okay repeat once it is my project development in real time my project may be a controller my project may be a service my my project may be a diot as of now to understood uh you know our guy copy paste this code what is the code here i am i am depending on writer team so it is my writer so it is the okay writer class it is if you go directly there it is a problem one second it is a writer class it is see how this okay writer is there because it is in simple class stream so my writer is i have a writer and i have a pen first example okay it may take time please concentrate okay if i write here notepad also you can understand easily java okay now here's your next one what is next one third one third one is ink team ink please no why i am copy paste here in three classes we can use at one stream that is the reason only i am okay writing here see my writer is a i have a pen interface pen interface is okay depending on some pen interface has only one implementation class as of now that is fountain pen my writer is okay depending on pen my pen is okay depending on ink means only one implementation class is blacking here what happened are we using here constructor injection or excitatory injection see we are constructor i am injecting my targeted object via constructor i am injecting my targeted object yeah whenever you are using your okay whenever you are using your object via constructor it is constructor injection you are calling interface you are not passing class whenever you are communicating between two objects always recommended go for interfaces not for the concrete classes that's why you are using here interfaces you have your interface also in our code it is my interface my interface will have implementation class is called this one so writer is calling to trend pen is calling to ink ink also i have a one simple interface ink will have two methods one is get color here overloaded those override here black get brand name park have you created anywhere new operator is developer is creating this new operator no developer is not creating this new operator how it happens we are only creating how we are creating bins inside of the beans how we are preparing please concentrate bean id first to what object i should create first to what object i should create i should create ink ink itching you are creating black ink class is class is called com dot three note echo dot black ink black ink please try to understand now next one bean id be an id see if you see my blogging exactly what i am going to write i am trying to use here that's it i am trying to close okay what is next to bean what is up next to be in team next to bean is equal fountain pen how to write this calm dot sterotype fountain pen but it is okay depending on what it is depending on what it is depending on ink how it is okay depending on ink how it is depending on ink how it is depending on ink i am using constructor hyphen arc constructor hyphen arg reference preference black ink who will write developer will write all this stuff developer will write all this stuff developer will write all this stuff next one constructor okay next one last one is bean bean next one is beans next one is beans now what i should do here it is a fountain pen is done now i should go for writer you should write you should do right you need to use which one see always know what i'm trying to do here in my code in my java code application context is you called new class path application context is equal to new class path xml resource application context here you should load your xml file what it will do whenever this statement it will be executed it will load whole all these bins information into your memory it will read this metadata dnad means a reference it will created this spring container okay instead of the container all the objects are available what you will do object should not get to be enough objects to dot get been off what would be happened objects dot get been off writer now what you got see in your real time you don't know your project to make you writer another project to make you credit card another project to make you a health card so that's why they give this a craton type as object object means any kind of return type it would be available application context is equal new application class path xml resource would be executed whenever this statement would be executed now what happened you know context dot get been would be created context dot get bin but we don't know in our real time which object maybe writer may be a card maybe we don't know that's why spring guys is given this written type is called object whoever want they need to type cast from object to to their own object that is called writer that is called writer all right writer writer context to dot get been off this one team context to dot get been off this one team hope you're clear everyone now here see so because of this okay return type is it is not a user defined class it is a predefined method predefined method always spring framework has given object only because now usb spring framework don't know what type of object you are trying to accessing you may be writer or anything so now you got writer what you are calling simply writer dot now you you got the object writer dot write method write a dot right and never this statement it would be executed flow will go to here because this writer is already dependent on this pen object now you have you are holding this your writer object will be holding this open object we are this pen object you are calling this right to where this inside of the writer automatically ink object is there we are this object you are calling ink dot get color ink dot get to brand if you go into dot get color is a black ink dot get brand is the parker working with the black ink of brand is parker now if i run this run as java application writing with the black ink of parker team no good okay next one now what is the next one see so okay instead of you will give big big names like constructor big bit in names like this you can go for c you can use either one is okay c c colon c colon ink reference c colon pen reference instead of we will write big big one you can write here c is available from this name space t so both are same but instead of we will write the big names you will write this in your application context new class path xml application context pass this xml file that's it that's it context dot get bin get bin has five overloaded methods how to give only bin id how to view class name how to give both the bin id and the class name like that we have five overloaded methods are there right click on it run as java writing with the black ink of parker brandt that's it any questions team first example any questions team first example any questions no question steve no we'll see now second example same use case team like a second example but my code is not changing anything my code is awesome what is your code c my writer object writer object is depending on pain only but earlier constructor now you are giving center when you should go for constructor injection when you should go for saturn injection but now my object is your writer is a dependent object it is a source object you are injecting your target object via sector you are injecting your target object via setter is called setter injection so now you have a writer writer is okay depending on what depend writer is depending on pen pen is okay depending on ink pen is depending but how to write here how to write here important same core team same code nothing change anything same code see how to write earlier constructor injection now shutter injection how to write this saturn rejection there is a element is called property there is element is called property property here property it is saturn right name is he called what is the name you are giving them what is the name you are giving team pen what is the name you are giving then okay inside of the your writer what name is there that one thing here what is the property name is equal it is depending on ink refugee gold witching kitty black entity that's it if it is constructor here constructor argument if it is sector here etcetera argument and another way you can write instead of you will write property you should give people instead of sir this property too much of big okay i can't write means directly you can write here now it is ink ink refrigerant black entity so code is same instead of in our code constructor now you are injecting what is the definition of the constructor injection the dependent object is injected into a targeted object via setter method is called in shutter injection wire method is called a shutter injection constructor injection the dependent object is injected into targeted object via constructor injection why a constructor is called constructor injection teams understood or any questions so the concept is same for here also application context context is called new annotation config application context see nothing is okay instead of your actual xml file it will give so here sector iphone config.xml you got this same output or not so now you can go for same p name space so you can go for p namespace so you can run this application also you will go sir this one understood so did you understand okay examples of constructor injection under examples of saturn reduction when you should go for constructor injection when you should go for a shutter injection i will explain did you understand what is the example of constructor injection and an example of shuttering rejection did you get it sir all okay everyone everyone did you get it sir please no good no difference between constructor injection and receptor injection when should then we should use constructor injection and saturn injection very very important very very important you have any space yes please try to understand constructor injection certain injection number one if the dependency is mandatory that means a is depending on b a is depending on b hey without b your a objective should not create okay without be your a object should not create a team okay without be your a object it should not create if the dependency is mandatory you should go for constructive injection if the dependency is optional the dependency is optional hey if you are not passing c in simple example take one simple example test maven project another project and i haven't project no need actually either one is okay calm dots test so simple for posting in your real time you will write uh this kind of thing simple for p versus java class e com.com b please concentrate okay now this dot b is equal to b now please concentrate now i want created the a objectivity static wide mean string rvs so a a is equal nu e i cannot create a h because a is mandatory b if it is constructor a is mandatory bt means if the dependency is mandatory you should go for constructor injection see let us assume that it is not creating using constructor let us assume that i am commenting all days are rda here i have setters and getters now i can create a object a a is equal mu a your shutter interaction you are see object is created whether you will be set to b or not it's all up to you if you will set it is working if you will not set what happened default what is the default value of the object here the default value of the object will be here null here it will give us a null value sir understood sir any question sir see the dependency is mandatory you should go for constructor dependency is an optional you should go for shutter injection constructor if the dependencies are monetary if the dependency is finals all are here it would be final here may or may not be final the dependency is non-final dependency is non-final now when there is cyclic dependency it is not support how simple you have a b is depending on a depending on and b is okay depending on a okay b is okay depending on a understood team now here see now please try to understand here please i could try to understand here to create a object i need a b object to create a b object i need a object this is called cyclic dependency and there is a cyclic dependency constructor injections are not possible whereas here whereas here here when there is a it is possible for it is possible for cyclic dependency it is impossible for cyclic dependencies it is possible for cyclic dependency understood these are the use cases team and i should go for this and i should go for this so you can make your note we can make our sometimes okay interviews are asking how shattering injection also can how this shutter injection also mandatory also option is there the answer is yes it is there is a dependence is optional means default if you want to make dependency also is monetary means there is annotation is called ordered required means we are forcedly we are forcedly make dependency dependency as mandatory for central injection we are forcibly we are making a dependency as mandatory for saturn injection understood how to use with the help of other rate required annotations with the elbow for the right required annotations are a clear team any questions team so this is what difference between saturn injection and constructor injection thing now we are good okay now next one d what is next one see we have seen till now we have seen till now only for xml basic approach how to use xml xml using constructor okay xml using saturn introduction so if already xml is there so we did application development development using using xml using application development for constructor dependency injection comma sector dependency injection using xml configuration using xml configuration if already xml configuration is there if already xml configuration is there why we should go for java config difficulties are drawbacks drawbacks of xml difficulties difficulties are drawbacks of xml difficulties are drawbacks of xml first learn xml need to learn xml xml to work with xml config need to learn xml to work with xml configuration means to write all this how to write without knowing okay xml without knowing like xml code can you you can't write right second one there is no type safety what is type safety xml no type safety no type safety if we pass wrong reference also it will consider if you pause wrong reference also it will consider if you pause wrong reference also that means go to here you will give here abc he will give here a over book xy your xml don't know right xml will treat it as it is a string that's it xml feel like it is a string until unless if you run your application then only it will give error but until you run the application compile time it will feel like it isn't correct only until no such bin definition exception now been named with this one what's to team so that's why your xml is not a type safety your xml is not a type safety please try to understand team how to write where to write now third one that is here here you can write xml can't recognize recognize the error during compile time during compile time during runtime during compile time doing it would identify it run time only so no typeset these kind of issues will come no type safety these kind of issues always would come by mistake while you are writing if you add any one space if you had any one extra property also necessarily it would give error okay now third one no what is third one no third one readable key readability credibility means xml and java java in different places xml and java in different places so need to keep switch need to keep this switch xml and java in different places need to keep need to keep switch need to keep switch from newton keep switch between [Music] xml gamma java hfx which affects with effects readability of the code of the code of the code of the core team understood [Music] [Music] no fourth one means what is the readability means see your xml is available here java is available here how to switch your xml to java you should go again if you want to come come to xml again if you want to go again if you want to come xml means the switching would happen the switching the switching would happen from an xml to java config is somewhat difficult is somewhat difficult understood now last one is maintenance first one is maintenance maintenance thing if if too many configuration then difficult to do maintenance then difficult to do maintenance if too many configurations then difficult to do maintenance difficult to do maintenance some duplicate ids might be configured some sometimes sometimes sometimes dependencies ids might be sometimes you could duplicate ideas sometimes duplicate ids might be configured [Music] so now what happened if too many are there what happen this name by any chance here writer name here writer name should be same understood so it is a problem thing it is a problem maybe duplicate will be there understood [Music] if a duplicate is there again it is the problem to overcome all this problem we should go for java config did you understand team why you should go for java config if already xml is there why we should go for java config team anyone can explain why we should go for javan config team if all the xml is there hope you got a team got it everyone so need to learn xml to work with the configuration next one type safety type safety means don't know whatever you will give it will take as a compile time run time maybe a problem will come third one readable is there is no readability because your xml is in somewhere under java is somewhere out to the readability the last one is maintenance maintenance means if too many xml lines are there what is the guarantee being id you may add duplicate if you add duplicate again it is a problem okay got a team now to overcome these all the problems to overcome these problems we should go ahead with we should use we should use you should use java configuration to overcome these problems we should use java configuration team to overcome this problem we should use java configurations team any questions team now what is java configuration now what is java configuration team you will be able to know okay shall we start java config everyone shall we start java and config okay now we will see java configuration city the first annotation in java configuration first annotation in java configuration yeah or the rate configuration t or the rate configuration what happened public class you can give anything java configuration you can give anything now at the red configuration or you can give java convicting so java configuration is used to replace xml with java config now here you have how the xml in basic xml beans inside of the beans what are there okay how to replace the xml with java config one simple use case we'll see it simple use case we'll see simple use case team here is my xml config this is my okay okay xml i have a bean steam i have a bean bean id bin class like that i have all okay if you want right he'll take one of xml file here he'll write it okay it would be easy either constructor set or whatever is okay for me we'll take one xml we'll convert this xml into java config it will be easy let's this is xml how to write java config how to write java config c student team wherever beans are there these beans will be replaced with beans will be replaced with earthright configuration beans will be replaced with red configuration public class java country public class java please try to understanding very clear team this beans is replaced means your xml is replacing with java configuration how to use this java configuration where to use this java configuration i will explain wherever bean is there you will be replaced with how many beans are there here three beans are there bean tea bean wherever id is there public fountain pen id return new from then return new content please try to understand no next to be in team what is next to be b next bean is focusing is sorry here it is black into team sorry first one blocking kitty it is a class t pattern type done okay now here's you it is otherwise bnd got the red bean it is found in good but this fountain pen is depending on what black ink black ink on tail pen is depending on black inquiry we are applying dependency injection via constructor that's why it is called constructor injection that's why it is called a constructor injection constructor injection [Music] okay now okay next to one t what is the next one next one c next one here what is there here here writer here writer here what is there fountain pen fountain pen so here what we will pass down then when you will pass under now see we are replacing completely wherever id is there here it is called id it is called class name it is called your bin element it is called your bin element team see please whenever this statement it will be executed in your xml in your xml in your xml in your xml these this underrated bean is nothing but bean ide being fountain pen is nothing but fountain pen is nothing but it is a class name class is equal method name is nothing but ide idt idiot look understanding so that's it it is your this is nothing but your reference your target object it is nothing but your target object now that one here you are applying your dependency injection via constructor it is your target object it is your target object understood it is your target objective any questions team any questions please ask any questions no here's no we are replacing your xml with java configuration authorizating configuration is used to replace your xml with java config bean element will be replaced with other right b id class will be replaced with this method name if it is xml how to load the ok xml if it is xml how to load the xml application context context is equal new annotation new class path xml new class path xml application context here you need to write here xml file if it is java config what happened you know if it is java config whatever you know application context context is equal new annotation config application context here you need to give java config.class please try to understand team you have a configuration configuration is maybe xml configuration is maybe a java config if it is xml i should use this class application context is an interface there are so many implementations are there few of the implementations are class path xml application so we can write sir i will explain we are in starting stage only right i would explain multiple and all shrikant we are in starting stage right circle just i am introducing a configuration class i would explain all in later upcoming okay application context context is equal new annotation config application context application context is equal annotation application context it will load the xml file it will load the java config it will load the java configuration in the both either xml or java configuration the preparation of the you know it will load the hole into your memory and it will created the object that ioc object is nothing but it will create the container means it will look referred forward using context inside of the container what would be there inside of the container what would be there here here it would have writer here you would have one spreader is there then you would have here pin then you would have here writer is calling to this pen pen is calling to pink okay now here see so the concept is same how to get here both the use cases context dot get been off get been off you need to use team here brighter t context dot get been off you should use team here writer team that's it so always this return type is object team how to convert your object to normal class writer team you should give writer writer that's it that's it here understood here any questions here any questions here now let's see i will show you how it is get it here so till now we have discussed only two annotations on the other configuration another one can we clear everyone now let's see i will show you this one java config constructor team code is same nothing you are going to change your code from pen you are calling here from the ink you are calling so from pen you are calling ink in ink this data is dirty now here see how the my spring config cc any doubts in this spring config what are the problem with xml shall we start one by one problem how to overcome by using spring what are the problem with the xml need to learn xml2 need to learn xml to work with java config no need to learn xml no need to learn java config also because it is already java right what are you going to write extra here nothing first two point is advantage second point type safety yes instead of passing inc if you are passing a visit it will give slap like another example if you want to give okay someone it won't stop it will take but this config this config java can't be compulsory you should pass the supported value otherwise you will get an error see understood team so here type safety is good next one readability whatever you want java is also here configuration also here you can easily switch from java to config config to java you can switch how many times you want you can switch it it's not a problem no last one maintenance if too many are there if too many are there what is maintenance if too many configurations then difficult to do maintenance difficulty maintenance because some duplicate ideas might be configured but in java if you are trying to write the same methods it will give error there is a chance to write duplicate ids in java you cannot try to duplicate idc for two methods with the same name java compiler will tell it is an error your class should not have two methods with the same name it will give error so we can overcome all this we can overcome or not what are the xml problems are there understood sir we can overcome all the problems using java config any questions you can ask oh here see okay now here go to your main method to see the nrc xml master now application context context is equal application contextual application context dot statement will be executed what happened now whenever this statement would be executed whatever now it will create the memory and all it will go to your jvm it will verify this class is present or not if it is present the corresponding class object with the corresponding class objective will be now if i run the application c you got the output or not okay now next to our scene see this is sir what is the question some projects are still using xml over java config sir yes they would be using world war sensor due to some no scratch development using java configuration trust me no scratch project using java is it some projects are started now or long back long back at that time people don't have time or don't want to take a risk to migrate to java convince no one has started yeah it's a long back means legacy one legacy project compulsory it was started with xml only if they have client will have funds they need to migrate to java config or spring boot if client don't have funds they should continue with xml config okay now so till now we have usually for what is constructor injection we are using for all our java config with constructor injection we are using examples here first example we did constructor injection using xml config setter injection using using xml config same thing constructor injection using java config constructor injection using java config sector injection using java now with cd now we'll see go to here another one java config constructor injection see now it is a saturday see instead of you will write first one is blocking next one fountain pen fountain is equal new fountain pen okay now your black ink is your fountain pen is a depending on blacking understood you are found in penny jacket depending on write rejected depending on pen now you will get a pen here that's it now how to load this see your code wherever you have code allah constructor only rl shutters only your code wherever is there setters only now we should go for runner understood sir that's it that's it any questions any questions team all are clear right all are clear next example is very very very very important next example is very very important what is very very important okay next one so we are using xml is okay how to apply dependency injection using xml and java config but what this spring guys will do either it is xml or java config what this spring guys will do why should i write that much of code why should i write that much of code in xml alt shift to team now here what your screen guys will do why should i write too many lines of the code too many lines of the core team please concentrate please concentrate if it is if it is bin only it is external what is your java configuration what is your java configuration java configuration this is your java configuration [Music] now in your project you have 100 classes are there 100 beans are there do you want to write 100 bins manually do you want to write this 100 bins manually no i don't want to write all 100 bins manually in my project if you have 100 beans are there do you write 100 bins manually no we can avoid this whole no need to write you can avoid this whole no need to write how how is simple we can we can reduce the using using using other writing components for the rate auto wire annotation we can reduce the we can reduce the boilerplate code using other red component or the right auto wire using authority component heart rate we can reduce the we can reduce the we can reduce the more configuration code using other written component other dot over here we can reduce the more configuration code we can reduce the more configuration quality okay how to reduce how to reduce c here it is very very important how to reduce see how many classes we have how to reduce how many classes we have we have earth rate component public class writer forgot about what is there inside of other red component here public class fountain pen public class public class black ink okay you no need to write here other red component is nothing but a bean only other company is nothing but a beer only how your spring knows it is a bean how your spring knows all the classes are beans if it is xml you should write only one entity component scan base package is equal calm.star component dot base package is equal to com dot c naught equal dot star that's it this component scan component scan component scan base package is equal to com.st during your your this xml configuration during your application startup while loading this xml config it will scan in this package is there any component classes are available or not if it is available it will created the objects in java config how it will lose there is a annotation is called other rate component scan annotation is called authority component scan i would explain practically base package is equal to com.st base package is equal to com dot question base package is equal to com.st understood to you understood team so you can avoid so much of bearer blade code then you may ask questions you may ask some questions now please concentrate okay okay please how to earlier using constructor injection you are able to inject object now how to inject how to apply the how to apply the dependency injection how to apply the dependency injection how to apply the dependency injection using are the rate component answer is the rate what over [Music] is used is used is used to apply the he is used to inject the is used to inject the target object into source object inject the target object into source object inject the target object into source object inject the target object into source objectivity can inject over a constructor other data wire can inject oh yeah [Music] field also this is one extra properties oh yeah field also is available here are you are you clear team how it is happening we will see clear practicals we'll see how clear practicals will see but as of now using as of now as of now using authorizing component another data wire we can remove most of the configuration code you don't need to write too much of code you don't need to write too much of code here everything you should write it here only you don't need to write too much of code too much of configuration code authorizing component to data the configuration code i would say how many ways how many ways configure a bin how many ways configure been in spring answer if it is xml using authority bin if it is java config using bin xml bin java config using authority to be now next one next one if it is for the rate component there are three ways i would explain sir when you should go for a ready bean and you should go for alternating component i will explain clearly okay there are in three ways three ways we can declare a bean in spring one is using xml another one is java config another one is annotation approach another one is annotation approach team another one is annotation approach team are you creative now no good now the next thing how to apply this till now we have seen next one in depth of component and all we'll see if you see here next one auto wiring constructor team now what happened you know before that i would explain no he or she [Music] okay class level now if [Music] if you will not declare any name to or the red component then default then default name as class name we can we can configure our own name too for the red component we can configure our own name to order it configure our own name to configure like credit card public class credit card if you will specify okay if you will not specify if you will not specify if you will not specify team then what happened default this name only will take by start with small letter camel letters or you can give xyz no problem your experience it is the pain reference id it is a bin id it is the class name t it is the bin id it is the class name t okay now i want to go with this simple one i have class a i have a class a i have class b i have class b unfortunately what happened you know here it is available in packages called calm dot c note e it is available in package name is called com.some series absorb whatever it is it is available in the package is called com.ht dot or com dot abc something no please concentrate now what should i do how my how my how my spring knows if it is xml if it is xml you don't need to write too much of code beans you don't need to write any code beans beans here what you will do you know component scan base package is equal com.ht now what happened please try to understand during your application startup it will try to scan what are the classes are representing with the red component those classes objects only it will be created those classes objects only it would be created okay now my a is depending on b my a is depending on b how to get a how to get b into a b b b b b how to do public a b b this dot just try to understand this dot b is equal to b t but earlier u inside of the xml you are able to configure earlier inside xml you are able to configure beans and also their dependencies also now you are not configure you just to using other red component scan how your spring knows on top of this constructor you should give operator to it on top of the constructor you should give him on top of the constructor you should give her a data where earthright auto wire has the responsible to inject the target being into to inject the target being into here now another one how to use acceptor it is for how to inject my bean auto wire constructor injection how to inject my bean this dot b is equal b here i am injecting my b into a with the help of sector injection it is called applying sector injection [Music] applying sector injection now please try to understand team please try to understand now last one is how to apply this dependency in direction create bb that's it how to apply here here also we have arthritis over here it is field level injection it is yield level injection you have a constructor injection auto wire you have in shuttering injection auto wire you have a field level injection auto wire but without writing any code here we will take care spring will take care component scan means it has the responsible to scan all the classes while planning is there any dependencies also is that this component scan will take care everything during your application startup only now we'll show you practically no what package you have given team here base package what is the base package com.xenotech whenever you give here base package it will scan only it will scan the classes only it will scan the classes only of that package only now is it com.stab com.abc is available under com.st please respond team now do you think our component scanning will scan b and assume both are not it will scan b or not component scanning is can be or not no right see no remember remember team when you add this package name it will add root package under the jade packages root package under their child package com.stabc is the child package or not com.st dot abc is then chilled package or not yes if it is field one enabler you will give com.st means it will scan all the classes all the classes of com.st and its shield packages and its child packages now is it in childhood package.com.st no right easy to chill the package no right in this case in this case what will do you know how your spring spring will not recognize if you are not specified here you should write comma com dot abc now it will start the scanning of these two packages it will scan the two packages i will show you practically this one i will show you practically this one underscore team with very very important this component scanning if it is out of configuration what happened this package is equal to com.st comma abc that's it both are same i will explain to you when you should go for a java config and you should uh when you should go for a thread component when you should go for another pin i will explain slowly we have started right i will explain how component scan will work answer is how component scan will work okay answer is answer is using component scan using component scan or other red component scan using component scan element in xml our other red component scan annotation in java config at the red component scan in java config team now let's see it is my project structure i have a project name yesterday we have discussed about introduction spring framework introduction spring framework that means drawbacks of j to e j to e and importance of and you know advantages of advantages of spring framework advantages of spring framework next one what we have discussed yesterday what we have discussed yesterday number two we have okay discuss number three okay now what is ioc what is ioc we have discussed ioc what is ioc now how it works number four number four what happens what happens or you can say internal execution internals internals execution execution flow when we create and we create application context is equal context is equal to new when we create application context is equal to new class path xml new class path xml resource application context or annotation config resource and all we have clear look explain how the objects where the objects will be loaded and all next one we have discussed about what is dependency injection injection and its types and their types types of dependency injection we have discussed about central dependency injection we have discussed about constructor dependency injection we have discussed about shutter dependency injection we have discussed about constructor injection we have also discussed when to use setter injection constructor injection now sixth one sixth one started examples on examples on number one setter injection and constructor injection using xml configuration and immediately we have started what is the drawbacks of xmls if already what is the drawbacks of xml configuration there are many drawbacks in the xml configurations that we have already discussed if you want again i can okay i'm ready to explain so if there are many drawbacks one is readability another one is a developer need to learn more xml document another one is readability performance maintenance now here all we have so many drawbacks in our xml custody okay havoc explain developer need to learn learn xml learn xml yeah to work with the xml config no b another one is it's not your type safety means we can any mistakes also you will write right until you you okay deploy your application you can't able to know at runtime only you will be able to know another one is performance performance means whole xml file will be you know created yeah okay it will load your whole example it will use internally some second parsers like sax parser and dump parsers to read the xml document it will take more time another one is readability readability means switching switching from xml to java config readability means switch framework xml to java configure every time from java classes to xml it is very difficult another one is maintenance maintenance means if too many configurations are there then sometimes difficult to maybe duplicate codes you will write another one is it is not covered yesterday i feel condition based being declaration being creation is is is difficult condition based being creationist is not possible in xml conditional basically means see whenever you created a b if this bin is equal to not equal to null then only should create.xml you cannot write this java code inside of your xml you cannot write java code inside of your xml team you cannot write java code inside of your xml team understood you can't write here your java code inside of your xml you can't write java code inside of this xml hope you are able to understand see to overcome all these problems now here see now you should go for java configuration team we have okay discussed about how this sector in the induction and constructor injection using java configuration team please i will share all this nodes java configuration and what are the annotations we have discussed yesterday that i will explain now next we have discussed about see how to avoid so much of configuration you know here setter injection and a constructor injection injection constructor injection under field level injection using using auto wire using other rate component using using okay uh okay using using java config comma xml to config with the rating component without the rate component with the comma or the rate not aware understood no that's it this is what how how it will be exhibited this is what how it will be executed so now we have seen few of those examples of the examples how to how to resolve the how to resolve the conflicts how to resolve the conflicts conflicts okay conflicts interface with the interface with the multiple multiple implementation classes classes using using using primary annotation or the rate qualifier annotations team okay now next we have seen what are the annotations spring core annotations spring core annotations we have a discussion yesterday one is one is other rate configuration or the rate configuration now yeah we should tell don't buy her team can anyone tell how many connotations we have discovered of discussion yesterday can anyone tell team what are the annotations um yeah still can you tell me still what are the annotations team to anyone we have discussed yesterday auto wired um still anyone no one everyone is yeah yeah good still fast fast you should do yes yeah first yeah see that's the reason all your answers are correct theme but we will never intro you're asking if you will remember in this way it is difficult to give answer you directly you will start at your auto wire directly with certain authority import it's not a good how to remember easily how to remember easily these annotations yeah please team how to remember these annotations easily number one team please please follow me my i know my way of remembering shortcut it will be easy to answer interviewer first you know spring core annotation yeah yeah yeah please start yeah good actually yeah see first to this spring core started now java config started to replace the xml files what is the first annotation to replace the xml file you need to go for the red configuration see how to okay you are replacing your xml with java configure the red configuration you did okay now how to replace your bin element how to replace your bin element with at the right being that's fine now see the rate configuration isn't done at the right bean is done now see what is the c means what is the c means is there any way to reduce the configuration or the rate component how your java knows how your spring knows or the rate component class your springos declare a beam your spring knows declare xml tag how your spring knows that there is a class is representing without the red component you need to provide the red component scan how to inject the beams how to inject the beans from container you have to use arthritis so like that you have to if you remember in this way it will be easy to if any individual asking yes okay first order configuration will come then at the red bean will come then to replace the bean you can use your third component how the other red component will be that you should go for that component scan then you should go for auto wire then it is done next one i want to import my xml with yeah i want to import my xml with java configure the red import resource i i want to import my java config to java config you should go for the red this one then then we should go hey how to you know resolve these conflicts you should go for a rate of primary you should go for other rate qualifier these are the annotations we have discussed yesterday any doubts any doubts team is it makes sense can you remember easily how many annotations if you give okay one two three you can easily understand how many team yesterday we have discussed one people are asking what are the annotations you have used in spring core can you tell me you will be in the position to give answers for all the annotations if any annotation they will be asking you should tell is it clear them everyone any questions team you can ask till now this is what we discussed yesterday i will give [Music] this is what we discussed yesterday any questions team you can ask a team component scan mahesh you want again i will explain yeah see you can just you know the revision right revision now here see what the revision is asking first how to apply this dependency injection team i am i am using di i am lazy dependency injection okay instead of every time i am writing this dependency injection i am writing the c team yesterday we have discussed about dependency injection can be possible xml xml config and using java config xml config and java config now see no ct now please concentrate if it is xml config and java config what would be happen now please see here using a xml config you should do setter injection and you should do constructor injection using java config you should do setter injection you should do constructor injection all these things means developer has the responsible to apply this injection developer has write the configuration manually this is called manual configuration what is manual configuration developer developer has the responsible developer developer will will write configuration manually okay developer will write team okay have you agreed or not okay xml who will write the developer has to write this configuration is manually java config also developer has the responsibility to write this manually no other shortcuts here but what are the drawbacks with the xml over java config we have discussed it here but this configuration should be either xml or java config developer has the responsibility to do the manually if you go for auto wire auto wearing auto wearing then automatic configuration if you use auto wiring automatic configuration no need to write any configuration by the developer your spring framework will take care automatic configuration automatic configuration with the help of other rate component comma earth rate auto wired annotations okay now earth rate component is used in this case other rate component is used is used to make pojo class as normal class as spring bean authoritative wire is used to apply the dependency injection is used to create the dependency injection understood team please these two are type level annotation type type level annotations means that object needs to be created for that type but in dependence injection for java config xml config only constructed injection or saturn injection but for auto wire auto wired you have constructor injection we have shutter injection we have field we have field level injection we have field level injection all these three types we can implement auto wire with xml config we can implement auto wire with java config also yesterday we have discussed it all team but just a summary i am providing team who is going to process other rate component comma further it out over here answer is spring has provided some source code to behave their functionality the process of the process of spring framework looking for identifying spring framework looking for identifying presence of other rate component presence of furtherate component annotation under then the process of spring framework looking for identifying the presence of other red component annotation and then creating the object is called is called component scan is called component scan or the red component scan other rate component scan or other it component annotation detection is not enabled by default that's what i have explained that is it is default to behavior it is default behavior that is authorizing component scan disabled by default disabled by default we need to explicitly we need to explicitly enable it explicitly enable it we need to explicitly enable it next question team any reason why it is disabled any reason why it is disabled anywhere in the class path add anywhere in the class path if you are by default enabled these jars will have you know okay assume that you have jars of hundreds of the classes if other rate component scan is enabled then spring has to search every class in the class path other component will be let's assume that in project in in project in project there will be there will be a 100 jars in project 100 jars in project order component could be add anywhere in the class path anywhere in the class path if furtherate component scan enabled then spring hasht then springer has to spring has to search in every class every class in the class path if you want to work or the rate component okay very class in the class path so if every class in the class path how much time it will take it will take so much of time to avoid that it will take so much of time to scan whole the classes that's the reason if you want to work with authoritative component we have to enable other rate component scan explicitly that's the reason if you want enabled okay if you want to work with so it will take so much of time it will take so much of time to scan under to scan it will take so much of a processing time on scanning that is the reason what we are doing instead of scanning every to avoid this that's why by default it was disabled that's why by default it is a disabled by default it was disabled understood right to avoid this so any reason of why it is disabled means each and every class it should be verified now instead of every class we are now we are so okay enabled package level if the package is available only it will looks for that package only it will scan all the packages what is the package is available at the right component scan only that package only you can able to look into that understood so now to enable to enable alternate component or if you want to work with other rate component work with other component then we have to enable we have to enable it using other rate component scan annotation scan annotation enabled explicitly using xml configuration or java configuration by default it will scan current to package only if you are not providing this alternating component scan anywhere if you are not scanning a data wire anywhere but okay if you are not providing any package name if you are not providing anywhere by default it will looks far let's assume that we were not providing anywhere by default it will looks for current to package current to package it will always scan the current package current package what is there do you have inside of any current package or the rate component classes are there please correspond do you have any other rate component classes are there in current package no that is the reason you have to specify this package name you have to specify the package name understood or if you don't want to package name you know exactly what classes you can specify the classes also not only package based package classes also you can give one class you can do two class you can give a number of classes also you can give it's not only for only packages still if you want to improve your performance you know exactly what are the classes of authoritative component you can give that component also here you can give here writer dot class comma pen dot class comma blacking dot class comma that's it now you can run your application now you can run your application still you can avoid me so but instead of it will scan all this stuff it will scan only these classes only it will scan only these classes only if you know exact class you will go for this one that's what i am trying to say the syntax is authority component scan other rate component scan you have base packages if you have only one package then you should go from com.xenotech if you have multiple packages if you want to scan open this curly braces inside of the curly braces no need fully qualified name okay you are importing right it will take care how you should give here comma separating it with the you should give how many packages with you can queue you can give a kpc you can give xy n number of packages you can give it will scan all the packages under there still packages also same authority component scan not base packages base package classes what is the class name any class name a class name b class name whatever if you want to go multiple then a dot class comma d dot class comma and sum depends upon the requirement you should use understood in our project in our project calm down st dot com dot st dot spring dart com.st dot kst.com.spring spring dot beans beans we should go for beans here we are using here inside of the beans we have classes like c1 we have classes like c2 understand all we have classes inside of the beans i have again okay sub package i have again again sub package this sub package is maybe a core okay okay inside of the core we have c3 we have c4 inside of this c4 we have one more sub package that's that sub package is called core okay util okay something here okay inside of this util you should go see for you let's see how it is my project structure here my palm dot xml now let's start suppose you are base package is you called com.st dot string can anyone tell what are the classes let's assume that all our component classes what are the classes would be scanned can anyone tell me anyone my base package is equal com dot st dot spring what are the classes we would be scanned can anyone tell anyone all right okay new one team all classes all classes good so means it is i am giving here my root if i am giving here root means c 1 c 2 c 3 c 4 root and its tailed classes all it would be available all it would be availability please try to understand so now if i okay depends upon the requirement if i give this package is equal to com dot st dot core what is output t what is output t can anyone explain what is the output what is the output team core and all its yeah output ah c4 c5 or c6 c4 c5 c6 that's it we are good if i will give only beans and hope you you understood so this is what you know during your application startup what component scan will be provided so based on the package name or class name the corresponding you know yield classes it will scan it it will create the object it will apply the dependency injection also [Music] are we clear now shall we close this component story team shall we stop this component story so last one team people are asking see what is this annotation thing if you go for this configuration this is also component only it is also component only everything is component but what is mean by target type first one is retention means either this is required at the compile time or of the required runtime if the annotation job is at compile time here your retention policy at compile time if annotation is at run time it is at okay run time so it tells you the scope of the annotation what is your scope is your scope is at a compile time as your scope is at run time what is your scope retention annotation is to tell you scope of the annotation this annotation would be required compile time this annotation would be required at runtime what is the target hey this annotation where you should use only class level or only method level or field level if you see being right if you see bin it is at method level target is this annotation you can use at method level annotation you can use any other annotation type but it will be used at runtime try to understand this source code of your spring annotation stream authority target is used whether a target is used so very that method can be used at class level or method level or field level or constructor level or other annotation level other regression is usually for what is the scope is this annotation is used at compile time or is this annotation huge network runtime most of these spring annotations are at runtime only understanding yeah no oh okay next one thing what is next one as you told auto wire we are we are able to use auto wires for but you know field level injection constructor injection and all okay right so field level injection auto wire field level injection is not recommended because one we can't write unit testing unit texting unit testing as dependencies hidden we don't know exactly what dependencies would be next one we can't write more conditions on if it is field level field level internally will use reflections okay internally we'll use reflections now next one if the class does not have or threat component still we can still we can use the red component scan with authority b comma xml config means your beans that is that is it components can will work with the rate being comma xml config means the rate beam xml configurations at the red bean comma xml configurations xml configurations thread component scan will work with the related bean comma xml configurations understood it depends upon the requirement we may mix up of configurations okay so okay sometimes your spring jdbc data source comma jdbc template okay jdbc template restore template and so on etc does not have other rate component that is we should go with or the rate bean only we should go with what the rate would be annotation only we should go ahead with our derivative b annotation only lost in somebody in real time in real time we should in real time all the below combinations we should use below combination means a one is only xml config b you may use xml with java config c you may use java config with auto wire don't know all we should use team okay if you understand springboard the story will be different springboard will not require all everything would be taken care by your spring boot only anyhow okay that will discuss later now we are good team everything is good now any questions now last one team are there lazy annotation this annotation is used to create the object well first request will come and first request will come means instead of okay instead of scan and create the objects during startup during startup during startup but the rate lazy lazy no need to this annotation is used no need to you know no need to stop you know no need to uh start during startup of your bean i want i want at run time and ever i want whenever i need then only on demand i want my p one demand i want the b then only i should use this then only i should use this team now just i want to give one summary team this summary would be helpful to you what is that summary summary means no xml java config whatever how many use cases 6 use cases use case 1 use case 2 use case 3 4. 5 3 1 2 3 4 5 6 you can use only xmlt you can use only xml you can use only java config you can use only not over here no you cannot use only outward that is not possible why auto wire is required either uh java config auto wire is required either xml config otherwise how the component scan will work however the combination with either xml the combination with either java config is mandatory you can integrate with xml with the xml you can work with the xml you can work with you can integrate it with xml with okay java config you can work with xml you can work with java config you can work with auto wire all that's it so if you want just to note t note if we want migrate we want migrate if you want to okay if you use a book xml xml then easily migrate to other projects if you use xml then easily migrate to other projects it is just like replace replace example config with other config file number two if you use java config or auto wire then if you use java configure auto wire then difficult difficult to migrate from java to other flow other framework because you you you need to write so much of 40. understood now with this can we put full stop okay xml java config and all understood everyone last one team people are asking maybe five minutes i may spend time and you should use a primary and you should use the primary thing i would explain legitimate then you should use primary it gives them priority to one being then other bean stream this annotation it will give priority to one being then one being then another beans another beans we can't we can't use primary primary more than 1b we can't use primary more than 1b one bin that is it's kind of that is it's like switch statement if you are not specified anything default b it will give that is the way understood team so if you are not sure what is the if you are not sure if if you are not sure what is the default then don't use or the right primary annotation okay what is authority qualifier [Music] it is used dependency injection as by name by name by type means class name by name is a reference name it is used to setting name or alias name to bean alias name to pin based on qualifier it will execute corresponding backend system d i will draw one simple diagram i will draw one simple diagram please be unmuted i will draw one simple diagram team in real time what happened you know i have a one i have a one card info i have a one card controller let's try to understand the card maybe credit card service card may be a debit card i have a one card controller card servicing service will have a number of implementations why in your real time you should write interface and impl means this is the purpose credit card debit card may be green card it will talk to credit card diago debit card diego green card diogo it will drop to this database this database this database game starts now card info controller or this search is credit card service card service and appear [Music] debit card service ampl green card services now when our request will come in controller whatever you know how the card info controller code is there the rate auto wire or the rate qualifier if the qualifier is cc card call credit card service i am if it is debit card if it is green card what happened whoever is calling this controller that guy has the responsible card number whatever your work request card number comma cvv number undone along with this card type cc dc gc whatever it based on this quad type whatever qualifier will do your qualifier as the responsible to call any one of them not all right so under request make come to credit card under request may use debit cards 100 requests may use green card the corresponding back end in system your qualifier what it will do it will which qualifying object it will route the request to the corresponding object so that that flow will be executed [Music] understood this is the use case how how we should use based on the qualifier it will executed correspond to the backend systems for clear team then you should go for qualifier when you should go for being team are you clear or not or any questions team every one team others others team color clear now good team okay next to one t so now all are good now no they do real-time scenario uh sir i don't want to fear the classes during during start time okay i don't want to create a few of the classes during start times if you don't want to create a few of the classes during start time at this time we should go for at this time we should go for laser at this time we should go for lazy recently we have used uh one of the one of the in our production in our production we are getting some issue during startup only your app server could not find a few of the classes i would explain sir so by default it is startup quality will be laid in multi-threading or during more number of requests to one class even though it is not required at compile time but still we are loading during startup only what we did on top of the b we are using lazy on top of the bean we are using lazy actually if you use lazy right what are the advantages with lazy lazy on you should use on bean method if lazy annotation present on bean method spring initializes the bean spring initializes the bean only whenever okay request will come spring initializes the beam only and never okay request will come to if you want let i can i can explain one simple code on this lazy team if you want i could explain one simple code on this lazy this has introduced in spring 3.0 version okay so let me explain let me explain one simple code you can use lazy on top of the okay let's see why we should i want to create one simple java config create one second let me how to use and lazy once a concern what use cases we should take i'm i'm thinking just where are these classes okay let's see we'll start one simple only okay instead of a complex one we'll go for existing examples and we'll start i'm i'm creating one simple bean sir what is the simple bean java config sector or constructor whatever it [Music] is lazy java config lazy example lazy let's see there is this lazy this is the lazy annotation so if you are not using lazy what happened so if you are not using lazy water band if you are not using this lazy water pen first of all i don't want to create these as these are all as a all as a all as a independent t i don't want to create any different beans bean bean bean is okay all are ajo independent no need any no need any dependency injections and all just to we want to test we want to test if you just start the rate component scan one second first we will use the rate lazy rate lazy can be applied using other rate in configuration class you can use team other it in lazy you can use on top of the bill on top of the b and also by default i won't explain this uh during my scope stream because you will be understanding in scopes easily let me complete this coke stream because it will be mainly focus on scopes only default you are all your spring beans are scopes okay singleton only but uh how to stop default behavior i would explain okay let's we'll stop uh this one after scopes right i will explain okay everything okay because uh some scope knowledge is required to understand then you will get it easily then you will get it okay utility okay yeah let's see let's see team then we'll start every very important topic is called very very important topic is called scope steam very very important topic is called scopes okay let let's see how these scopes would be okay full and all will see practicality scopes day two will start after spokes you'll see this lazy also key day to start very very important topic team scopes spring sports team spring scope what is mean by scope team very very important team very very important what is mean by scope i would say i would say scope is scope is i would say scope is scope means lifetime t lifetime so primitive is easy only i could not then you have primitive in your xml file okay instead of properties you have okay you can do primitives also sir it is easy only i could not cover not a problem i can okay i can explain one more example primitive also okay at the end we'll see now here see scope is lifetime scope is lifetime t the lifetime of the scope is lifetime what is mean by bean scope what is mean by bean scope is lifetime of a bean lifetime of a bean in the container lifetime of a bean in the container bean scope is lifetime of every area very important please concentrate the lifetime of a bean in the container lifetime of your been in the container team okay next one see when when a bean gets created by the container so when a bean gets created by container and when it gets destroyed destroyed destroy editing okay when a bean gets created in the container and when it gets destroyed it is called bean scope it is called bean scope team it is called a bean scope it is called a bean scope tea next one connects to one day what is next one how many scopes are there in spring types of scopes in spring tea we have a number of we have around six scopes are there in spring one is singleton another one is prototype another one is request another one is session another one is global another one is application we will not talk about these three these three are usually for to develop okay web application like mvc-based applications globally you prefer to develop some portlet applications our goal is only to okay discuss about our goal is only to discuss about uh discuss about team what is request and single turn and prototype these two only we are going to use t these two only we are going to use t okay now because spring core scopes are only these two because spring core scopes are only these two hope clear everyone now first one is what is single 20 what is singleton singleton beans will be created whenever your container during startup singleton will stay in the container until it gets destroyed until it gets destroyed what is mean by singleton means only one object will be created singleton objects are only one object okay if you want to use a singleton whole application only one object it will be created it is called in singleton it is called a singleton means please very very important thing what is mean by oxygen hilton what is mean by singleton only one object only one object only one object to for whole application for all applications okay only one object for multiple requests only one object too far multiple requests is called singleton singleton is different spring singleton is different java singleton is diffracting it is for container level it is called a container level spring singleton scope is not same as single design pattern okay that design pattern is different this is a design pattern is different this scope is one object per container for being a definition it is called singleton here one object per container per bean definition very very important don't confuse now singleton singleton beans will be created created when your container created in your container created during container startup under on a desktop under desktop kind of a desktop it will make a destroyed during startup and it will stay in container until until it gets destroyed until it gets container destroyed please concentrate very very area of important i would say here singleton scope is equal container line i would say until your container is there then only your singleton scope is there singleton scope is not same as java singleton design pattern [Music] that is that is your java design pattern will be only one object for whole application here one container java and singleton design pattern is used for is used only one object only one object of our whole application only one object of our whole application only one object of our whole application that means now here see here i have been id abc class is equal abc let's assume that here whenever this statement it will be executed whenever this statement it will be executed for being definition only only one object will be created now if you give sir session no it will not say reducer so it will not save sorry now been id abc1 class is equal abc now what happened here now what happened here please try to understand a new object will be created for being definition if you take some configuration it will with new id with new id means in your container means what happened it is of singleton please try to understand if it is your container now here what happened [Music] here one object will be created here another object would be created one object is abc another object is abc1 another objective abc1 so two objects would be created in it's not like whole application one bin that's wrong one being one object for one container please concentrate now if it is no if it is what is mean by prototyping type i will explain examples of practical look you will be able to know prototype multiple objects per beam definition per container multiple objects for bean definition per container whenever there is a need for the bean whenever there is a need for this bean new object will be created it's like uh you know it's like you can throw whenever okay it's like create the object okay it's like okay now spring container always holds references preferences singleton beans which it has created as as it is reused using that okay reference using that reference hope we know that now what about prototype spring container does not please concentrate it does not hold any reference of the prototype which it has created once object is completed of the prototype type b then it will go to the garbage collector by the jvm once object is completed of prototype then it will get gc garbage collection by the jvm it will get garbage collector by the jvm so now the biggest question is and to use turn when to use a prototype is very very important bean scopes an application run in multi-threading environment especially bean scope is very very important see by default not if you are not specified any scope by default by default all the spring beans are single done by default all your beans are singleton scope by default all the beans are singleton understood sir now please concentrate by default all the beans are singleton now very very important now here see i will show you practically if it is singleton how can i i can i prove it is either you will use xml if it is xml in xml config how to use b id black ink class com.st dot blacking scope if you are not specified by default it is singleton or else you can specify if you want to specify here you should specify here prototype if it is java config you should use there is an annotation is called authority scope here you need to specify specify the scope either singleton or prototype if you will not decry then default scope is singleton only default scope is singleton only understood how can we specify here if it is xml go to resource spring config if you will not specify anything go for this one have you specified anywhere scope you specified anywhere spoke stream here no if you are not specified anywhere default every bean is a singleton default every bean is a single ton default every bean is a single turn you want to prove so now here see now we will see it is coming again how to know whether it is a singleton or not system dot y dot println writer object is writer now run as java application see only object okay hash code will come but same thing i would say one i will comment this for some time why do we need this is it same or not that means from the container it is getting same bean or not even you will try to get that bean 100 times okay all are same or not but what i am what i want to do here intentionally i am trying to create one more bean not same another bin id or writer new b id let's see team actually it is same but let's say you are trying to create new one blue new let's see team please try to understand but actual use case we may discuss for one hour only on the scopes very very important how this scopes will be used in i will explain how your tomcat default threats are will be there please try to understand what i would explain okay everything okay now here see no run as this even though your object is singleton but for being only whenever you are creating newbie it is new object or not please don't confuse it in interviewer spring singleton is the same as your java singleton no your spring singleton is one bean singleton beans will be created one object per container per bean definition if new bean definition is there ano another objective will be created with another one team are you following team everyone is okay or not all fatima all clear sir are you getting sir okay now we'll see here now we will see team next one we'll see now please and try to understand try to understand try to understand okay next one please try to understand okay next one so even if you this is okay fine everyone is find this one now next one is the next one is team very very important what is important stuff we are going to see now different use cases of this singleton and the prototype different use cases what are the different first i will use it's a simple one i will use a simple one is i will use simple one this scope is equal to prototype now what happened i will go to xml xml i will stop this one no need just for showing i'm explaining here go for writer scope is equal proto type [Music] scope is equal to prototype no run this application observe here the scope is equal to product type every request is new object or not every request is new object or not every request is new object or not i give by default by default you are by default by default your singleton objects are your spring beans are single done if you make it as prototype then what it would be happen if you make it as prototype now here what it would be happened so yeah now here see if you give prototype every object is its own hash code it is getting yes every request is a new one here okay every request is a new one here now see now actual game starts now what is actual game starts now means very very important team what is actual game starts here please try to understand when you should go for single turn when you should go for prototype first i will use this combinations scope combinations what is scope combinations number one i have a to class class a very very important please please you the introversion asking this class b i want to inject class b into class a i want inject class be injected into class e that is class a is depending class a is depending on class b class a is depending on class b class a is depending on class b now that is now here see please try to understand here number one use case use case one both are singleton [Music] use case one both are singleton a and b are singleton objects that means singleton injected into another singleton b one guilt and injected into another single time now what happened case two i have two classes here a comma br prototype one singleton one prototype type one proton type injected into one prototype injected into one prototype being one singleton being injected into another singleton bean one prototype being injected into another prototype being how it happens very very important in real time case three one singleton will be injected into a is injected into another prototype one singleton will be injected into another product type a is prototype b is one singleton injected into one singleton injected one singleton bean been in injected two another prototype b case for a is singleton b is here one prototype will be injected to injected into another singleton these four use cases we need to practice team very very very important sometimes you know your dependent class will be injecting into you know sometimes your dependent classes will be injected into your dependent class no no no what happened so at the time we should be very careful team i would give one one statement this statement why it is you will be able to know never injected shorter life would be into a longer life would be what is the difference i would explain to you never injected shorter life would have been into a into a longer life would be longer life would be in your real time what happened actually real time how your project to flow in your real time your project to flow in your real time you will have controller you will have service you will have duo you will have this back end is database under see when we should use then we should use singleton when we should use singleton and prototype and we should use singleton and prototype okay the questions are is your is your controllers are singleton or maybe here your controller is depending let's assume that here a is a controller b is a service how to do if a and b are in singleton how your application will see if a and b are prototype how your application will see if a is a prototype under b is in singleton how it works if a is a single turn and b is a product type how it works one prototype being injected into another singleton how it works now we will see all these things practically did you get a team basic what is singleton what is product type team singleton means one bean one bin singleton is not same for your java singleton design pattern java and singleton design pattern is usually for whole your application only one object will be created our spring singleton will be used for one object per container per bean definition if you are trying to create in single container two bean definitions then we should go for it's not in singleton it's a two objects will be created for every bean definitions two object will be created for every bin definitions i have shown the practical example also we took also two here we took also two here conductors are here it depends upon the requirement we should use that all so it is a another one if you go for your here i have here two binocular definitions in my container if it is two binocular definitions means what happened for this one object will be created for this another object will be created if you are not specified default scope is a singleton if you are not specified default scope is on singleton but we need to see these combinations team what is these combinations so prototype means irrespective of this means always a new object will be created that new object already we have seen here if you use a singleton default is a singleton if you run see only one object but a new object new object has a singleton but on this object it will be singleton not c on this object it is a singleton you can give writer new one brighter new one brighter new to writer new to you can give but it is all singleton on this bean definition it is another singleton object see okay done it is also done if you change your scope is equal to prototype irrespective of this always it will be but all these prototype objects will be created inside of the directly in jvm only singleton objects only will be created in jvm and references would be available in our container your singleton object scope is during your container line during your container startup those objects will be created if the container destroyed those objects also will be destroyed but prototype will be is john depends upon jvm let's see case one team i am splitting into four cases case one what is case one what is case one single turn injected into injected to another another singleton b singleton injected to another singleton p another simulator pin singleton will be injected into another singleton bean if you take this one if you take this one now we can see a is singleta b is also single turning [Music] so now now what about one container only one object will be created one object for a and one object for bt one object for a and one object for bt now what happened even you will get it under request even you will get it under request a and b objects will be always only wanting very very important even you got 100 request for n number of request for n for n number of request objects will be only one t objects will be only one for both a and b it is clear team okay everyone this is clear everyone this is clear everyone now so case 2 d what is case 2 case 2 is both are prototype proton type injected to another prototype prototype injected to another prototype proton type injected to another prototype what happened here here a1 b1 a2 b2 a3 b3 that means for request one for first request for first request in our request one it will be happen here you got a1 here you got b1 for request 2 it would be happened whenever you got your request to do here it is a2 means for every request a new object will be created and you got requested three and you got requested three now here what happened here you got a3 as well as b3t a3 as well as b3t means for every request here is only one in respect here is here a is a prototype and b is prototype here a is proton type and b also is type means for every request for every request a new object will be created for every request a new object will be created for every request a new object will be created for every request a new object will be created now case three case three singleton object singleton object injected to prototype singleton object injected into a product singleton object injected to type here what is interested in please concentrate [Music] here what is interested one here you got a is prototype b is singleton singletar now what happened but a is prototype b is in singleton a is a prototype type and b is a singleton let's try to understand b is singleton [Music] a is prototype that means for every request a is one new objective will be created request one request one requested three request one request to request a tree [Music] here is a1 here is a2 sorry here is a1 means for every request a new object will be created b sorry a2 a3 but whereas here always b is only one so whenever a required b this a will talk to b to get the data a will talk to b to get the data a will talk to b to get the data here a will talk to b to get the data here a1 will talk to b1 a2 will talk to b2 a3 will tap to b3 here since b is again singleton no problem always here here b is a singleton no problem always you will get it same data to all these objects all these objects okay here this one the summary is here every request new a object will be created but b object is only once as it is singleton b object is only once as it is singled understood okay now clear no case for what is case for [Music] case for here somewhat interested prototype injected into singleton prototype injected into singleton that is a is a is singleton [Music] a is singleton and b is prototype a is singleton and b is prototype now here c please concentrate please concentrate it is it is now here what happened means every request a new object will be created is b1 it is b2 it is b3 here it is it is singleton right here it is a1 now i got let's assume that request one requested to request three request one request to request a three request one two question two so requested three request one no request to do no request three request one request to request three now here c but b will be injected or not we will be injected into a first request second request third request is it correct are any questions here team is it right team okay everyone so until the container is available for every single request same object sir if container will be destroyed in jagdis again new new object would be created right yeah see case for case for here proto type is b generally what is the definition of proton type here what is the definition of the product type here t definition of the prototype is definition of the okay every request a new object will be created here it is happening same here it is happening same or not every request new prototype okay every request new prototype every request new is it right teamwork everyone okay try team please yeah okay everyone everyone please correct or not case for yeah hundred percent it is not correct the reason is see yeah yeah yeah hundred percent it is not correct the reason is singleton objects are during your application startup only singleton beans are created during application startup singleton beans are created at the time only a will be injected into b so it will be injected same object it will be injected same object if it is not created again there is no chance of request is not coming to you directly to your be right during during application during application startup during application startup during application startup singleton beans beans are created during application startup singleton bins are created during application startup singleton bins are created at the time only at the time only a will be injected to be at the time only a will be injected to b during application startup singleton beans are created during applications startup singleton beans are created at that time only a will be injected b so it will injected so it will inject it so it will inject it it will injected same object if not created again if if a is not created again if a object is not created again very very important introduce question that's why never inject prototype into singleton never inject prototype into singleton never inject a proton type into singleton even though b is a prototype but it behaves like singleton only even though b is a product type but it behaves like singleton only singleton only even though p is product type but it behaves single terminally it behaves singleton only any questions here are you clear without understanding and all or any questions team that's why i gave one statement here what is the question sir when first user and submit any request with scope is singleton it will hold all the data in the particular object under first user next another second request to come if you are using same object it will be the problem so how to handle at that time you can give a a is a prototype sir see if the request is varied from every every uh you know okay the data will be added from every request go for product type the data will be same for all the requests to go for a single done i will explain when you should go for a single turn and then you should go for a prototype i will explain please let me know if anything okay any clarifications are required okay or not that's why i gave earlier statement here never injected short lived beans into longer lived beans now you came to know why we should use this now he came to know why we should use that one statement please go through that statement once never injected short lived into long lived object short lively means product type okay every request a new prototype would be created that's why it is called start line singleton is long live you should not do it you should not do it now we'll see when you should go for singleton and when you should go for prototype team then you should go for singleton and then you should go for prototype team and you should go for singleton and you should go for prototype okay now here see then use singleton and prototype so if if the application if the class will not have any instance variable then preferred single term then preferred single term if the class will not have any instance variable class that is class class does not hold any state class does not hold any state team class does not hold any state if the class does not hold any states happily go for happily go for singleton team happily go for singleton team understood happily go for singleton happily go for singleton any questions here if the class will have if the class will have if the class will have any instance variables bracket holding state because this organist and then preferred because instance variable will be varied from object to object for every request this will be variative for every request this will be varied for every request it would be varied here okay no depends upon the requirement you should use team wherever you will see it depends upon the requirement you should see wherever you will see that you should prefer team now here okay interested one is interesting one is where to use this now here this is about scope stream any questions on the scope you can ask any questions on this scope you can ask if you are clear then we'll discuss okay now where exactly we should use this lazy annotation see now first i will explain scopes practice then we'll go for it depends upon the requirement edges we can't tell okay depends upon the requirement either we should go for a single turn or okay you should go for proto type okay depends upon the requirement you cannot tell okay exactly which one is know where to use and all depends upon the requirement you should use it understood the difference it is you can't take exactly are we clear now now here see okay next one d so we'll see one one practical use case yeah we'll see this scope using java config all our product type so i got the red scope configurable order the singleton you have increasing kilton pen singleton this is called prototype this is called prototype okay now we'll see how to print and all we'll see now increase singleton see now you'll see all the use cases you will see in this example just for how to use scope in our java config remaining code is everything is same remaining code nothing i'm going to disturb how to use i will go for our own language our own terminologies okay instead of this code whether you may or may not understand i will go for our own style sir what is our own style i am creating i am creating our own packages sir here how with our own packages so that you can understand easily calm dot so you know take our classes beans i'm creating a class and i'm creating b class b class see my a will have a one constructor a this will be called b bb bb this dot b is equal to b now here public wired m1 public wide m1 return float value for oklahoma okay now plc system.out.println m1 method no go for this b team public wide m2 something whatever it return i plus one are written return what should i give first time is okay i value okay static value if i give every time it will execute the same value right okay return just i will do my only intention is only that local variable only will be executed if it is instance variable even if it is instance variable it will not be executed okay just will give an sop as of now bm2 method here it is void from a v dot m2 just cd i'm writing my own java config here it is at the right i don't want the authoritative component as of now yeah you can use it's not your problem i want to scope right okay now go for my own configuration a configuration or scope configuration now what you should use at the rate [Music] be done now i am expecting here bb here b i'm expecting here b b here b what is happening here return new b that's it why it is not happened here my b is injected over a could have here constructor yes bb is equal to okay written new yeah that's fine now we are good any questions team here any questions here t simple coding any questions team everyone i am i am asking any questions team any questions came here simple coding team i am not writing any code at all any questions team no i am giving scope is equal i am giving scope is equal why it is not configurable factory dot scope singleton configurable factory dot but when you go for a wherever you are creating b i am trying to b object is b now here c now i am writing one test method a main class application context context is equal new new annotation new annotation application context a config dot class context dot get been off context dot get been off context dot get bin of a a dot com the statement will be executed flow will be go to where you are a here i want to know how the a object and how the b object will be created here it is singleton system.out.println a is now let's try to understand here now if i run this if i run this how to test time a is only one be at red but every request it is a new one right how to test every request it is a new one since it is a single until that a 2 5 e 3 0 until you close the container same object will be returning same object will be written okay if it is singleton now my question is my question is if a is if b is prototype okay case 3 will see what is case 3 here case 2 is straight forward both of them same will come case 3 a is a prototype b is singleton a is a proto type b is a singleton how to give a is prototype now here see now i'm running earlier singleton means every time same now i am running a product type means a is always new one b is always turn yeah now two double five b is always cancer within three only b is always against with three only b is always with three only a always will get new one because a is a prototype will stop and will run again we'll close this container once how to close context dot set down context dot application context context dot oh it should come way it is not coming context dot shut down the container or close it if it is not come no problem what will do i will stop this we will start again run as mvn clean run as java application now we will see no it is not stopped this jvm is not accepted how the container will be shut down application context to dot one method will come set down way it is not coming close method also will come application context to dot shutdown not here after you got everything after you got everything now one second now my intention is how to set down okay you can sit down with the help of here also it should come how to insert down your container it is their team you can close your application context close application context how to close application context that's what we have it this one clean context like this one second will it be work oh it is annotation context context research semicolon yeah now it is closing see actually this context operation type is we are a type casting team close method is there we are typecasting this close method let's see here is i got the reference and i got the b now it is closed right next time yeah is always getting same a is prototype iq b is sorry a is i give singleton what is third case a is product type but my b is singleton oh reverse team a is a singleton here a is yes correct only this one but b is singleton a always it will give new one and b always it will give same one if you go here i am trying to printing a is always you should get new one because it is a product type b is always you should get how to get there b directly you can get it to b also directly you can get it this b one second time don't confuse why you should go there one second go to here configuration i am calling this bean theme here m1 method object is this 4b 9e why it is getting same every time because it is not a single turn it is a prototype go to a class right here constructor during constructor only while it was executing one second go for our own style here write a region here writer is an i'm just i am i'm using here prototype team in this product type fountain is in singleton peninsula type black ink also is a singleton t only writer is a prototype let's see it is a use case of this one oh i'm not calling any new request right that's the problem here in a i am passing always the same request that's why it is giving same if you are sending different request you will get a different uh hash code that is what i did here so now what i am doing i am passing one now again i am trying to call this bean means two two request i am calling earlier i am calling same this one only now i would call one more request means three request i am calling to whom this writer if you are calling multiple requests to this writer okay i would ask here only team why i should again i don't want switch here only i understood the problem always you are calling only one you should call this a only a n number of times call a call a call here a3 a1 is a2 is a3s a1 is a2 is 8 degrees now run as see because of a is a prototype every request it will be new one but b is always only one b is always only one team did you understand team even if you want to create here also b a n number of times you can write b is always only one where you are printing see for every you can call for every you can call a dot m1 a1 dot please try to understand if any doubt you can ask a 2 dot m1 a3 dot m1 please ok try to understand you are since it is a product type for every request a will being created as a new one but you call n number of times it is a for every request it will be new but for every request b it should return same value run same value please if you are not understanding please ask me i'm calling i'm sending four requests for four requests because it is a prototype for request every request a would be new new hash code but whenever you call okay m1 m1 is calling internally it returns the b but b is always same because b is the singleton that how many requests are there that many a request that many b request but a will be varied for every request but b would be same for all the requests team understood team team are you clear or not case three clear okay everyone can be clear case 4 is interested 1 now what is interested 1 case 4 is interested 1 good what is case for you know please concentrate what is case for you know reverse it is singleton it is prototype generally what happened a would be only one but b would get many because it is a property type now see here a is singleton b is prototype but see a also same object b also is same object if a is a singleton even you will call one last time also b also is getting a single turn only during first time your application startup only during first time your application startup only your a object will be injected into b object even if you'll give unlock request but even though p is a prototype but b is here acting as a singleton sir are you clear sir sir everyone sir are you clear everyone everyone no you got it right no confusions right all everyone no no confusions right yeah yeah good thing no heresy now no small question is forgot about singleton under product type now we are scopes are clear now are you clear this scopes now we have seen all the scopes team hopefully clear everyone's scopes and to use singleton we want to use prototype all clear now now we should go for i'll clear my team okay everyone here now now we should go for lazy annotation team lazy annotation spring lazy annotation indicates that spring lazy annotation indicates that indicates that a bean will be initialized a bean will be lazily insularized a bean will be lazily insulated the lazy annotation can be can be annotated can be annotated with the rate component connected with class level comma method level that means a for the rate component or the red configuration you can add at the red component of the red configuration with use for the red lazy annotation method level at class level what method level see the default scope bean is singleton generally singleton beans are pre-initialized during your application startup only way to to discover the errors to discover the errors errors in the if any of the errors in the configuration and are if errors in the configuration fourth one to initialize if you don't want to to initialize a b lazily we can use other rate lazy annotation in java config you can use the red lashy annotation in java config or use lazy init attribute attribute in on the bin element bean element in xml configuration in xml configuration based application fifth one [Music] understood sometimes if if we want if you want early initialize early initialize with or the rate lazy annotation then then use moderate lazy great lazy value is equal to false use of rate lazy value is equal to false please concentrate team hope you are able to understand lazy initialization means lazy initialization of being means a been not initialized until referenced are called by another being be be explicitly calling be explicitly explicitly called called that being from application context from application context from application context sixth one i i already told laser annotation is present on the class level means update configuration bean level means method level or the rate lazy annotation can be also used are with rate auto wired understood what the rate at over here this annotation is introduced in spring 3.0 that city team almost all all we did know no now you want to see what is the proof here go here same example i am going to take not any new examples i in here scope is not a matter maybe both scopes are singleton remove the scope if you remove the scopes default what happened default it will take as a singleton only go for here yeah go for here i have a one simple constructor a constructor be constructed oh about all our goal is not our goal is not okay if you want to later i can share this one like you may you may expecting practice right later our goal is not scope our goal is go for this a a will be calling this b during our startup only a and b objects are created even you don't need to call any these methods also methods is calling again one right no need for this if you start our application if our if you start your application during startup only during startup only your objects will be created go to here main the constructor got created why a constructor is not created why a constructor is not created a constructor also it would be called not called mean circuit should occur i should give maybe this yeah also it should be called sir i don't need this dependency injections also to be frank here our our case is for what how to load these beans i don't need this dependence injection i want to take one simple classes how to use it here that's it now i have a that's fine go for here if you start run see a and b are created go for a to be frank no need for this also no need for this during your application startup scopes are singleton a and b are created now go for b i want this go for your configuration i want to give this scope as a lazy now here see go for this one run as see only a constructor only created not creating the b when you located the b in every first request will be either you should call by this one whenever you called this one then only b will be created then only b will be created whenever you called request get context dot get win then it will go for your container start looking for this b of the class is on this one then only your okay what spring will try to create the object until until you will send a request spring will not created areas here if it is singleton means by default during startup your container only all singleton objects will be created run as java application see okay or not okay or not in team please concentrate i don't want to give lazy at here i want to give at class level you can give who is stopping so both are lazy initialization but here you called only one have you called a here no at the time a will not come a should not come only b only will come wait during startup you give a you give all are lazy if all are lazy means whenever you will send a request then only these objects will be created until that these objects will not be created now if you give here a a it should be created just you are calling now now run as java application understood the requirement team understood the requirement team team are you clear with the lazy one everyone team please let me know if you are not able to following okay let me know i would explain lazy means for what during you know during startup initialization i want to create my own uh you know i want to create it whenever i want at that time how to override default behavior of the your spring how to override default behavior of your spring then only we should go for this lazy one understood okay now done so all these are usually for lazy one we have a discussion team i have explained bean level i have explained this configuration level you can use instead of whenever you use auto wire right now now what happened if you use auto wire right don't use here don't use here if your a class is component b class also is component okay now go for here how to scan by default if you are not specified you no need to specify any base package default one it will take which one this one means here these two are available already so if you are not specified in lazy what happened during startup only it will take because these are the singleton i got it i want to give my b-class as a lazy now you will run it only a only will come b will not come when b b will come either b will be injected by others or b itself is called by your application context then only both will come understood sir we have implemented configuration global level we have implemented bean level we have implemented component level if it is ok xml means you should use i have given that also so sometimes by mistake i give lazy i don't want uh this little laser inside by mistake i give lazy if you give lazy means it won't calm both only a constructor would be called because a is not lazy but unfortunately by mistake i give this lazy no value is equal false hey please don't consider this lazy here okay see both are key team we can we can play like r d like anything team all these things all these things you are going to implement in our project team if you are strong on this core you can play games like anything thing let's we'll go for other stuff team okay then we are fine yeah good team now we are clear with this scopes and lazy annotations also now next example is very very interesting one is till 15 we are clear 14 scopes how to next example is how to read the properties values very very important to use casting next one how to load the properties values how to load the properties and get the values from properties file in spring how to load the properties files how to load the properties files and get the and get the values from properties files in spring team in generally how to load the properties file i have a properties file t let's assume that sample dot properties you need to write java dot util dot in util there is a code is called properties code okay p is equal to new properties file something how to write the code p dot load off sample dot properties file something i'm giving whenever this statement would be executed what happened you know it will load the properties file object it will load the properties file object it will created the properties file object and you know how to get the value string string name string properties name string generally will be storing user name and password get get property of your sample dot properties file username is equal to password is equal to welcome one two three or whatever once you will load the properties file you got the properties file object p dot get property now string password p dot get property of password get a property of fast working common requirement in every real time project how to load the properties quality you have to be very clear how to load this properties filtering you have to be very clear how to load this properties file t understood now now here see instead of you will do all this code instead of you will do all this code spring guys is given one annotation so how to load okay okay instead of you will write all this code instead of you will write all this code only one annotation that annotation will take care to load the properties file to load the properties file what is the annotation means are the rate property source you need to provide class path where is your properties file location if it is available in the resources only either you should give here absolute path or you should give here a relative path file path whether you should view here absolute path or we should give here relative path you should give here absolute path or you should give here a creative path this annotation is used to load the properties file this annotation is usually to load the properties file once you will load the properties file once it will load the properties file then what will be happened once it will load the properties file then what will be happened how to read the read the values from properties file read the values from the properties file one using environment object which is provided by this spring using environment class object this is provided by spring using environment using environment class object using environment class object this is provided by spring next one using the rate value annotations using authority value annotation using environment class object this is provided by spring next one using other rate value annotation using a thread value annotation using the red value notation understood so how to use now we will see practicality first environment object generally properties file will have your database details or all configuration information will be available till now in the this example if you see our last black ink here we are hardcoding values now instead of autocodings now we are reading from where these values from properties file okay instead of auto coding now we are reading these values from where properties file how to read these values for a properties file is not important how to read these values from the properties file is very very important now understood team very very important so okay instead of hard coding these values instead of hard coding these values now we are trying to now we are trying to get these values from the properties phi get these values from the properties file get these values from the properties file understood now here see now here's very very important next one it is a properties one i want to go for remaining code is same what is the code or the red property source annotation it will always looks for class path means in your project how many charts are there in your project or how many charts are there it will go to all this just it will go to all these jars it will go to all these jars it will try to get the it will try to get the you know properties file from the class path it will try to get the properties file from the class path understood try to get from the class path how to use how to once it is loaded whenever this statement it will be executed whenever that statement will be executed spring course scopes okay whenever this statement will be executed a properties file object will be created inside of your container inside of your container a properties file object will be created what are the values are there these values will be there these values would be created once it is happened right in your spring there is a class is called environment class this environment class is extends property resolver which will be okay see interface resolving properties again underlying what this environment class it will do see property sources resolver it implements the resolves the properties values against underlying set so this environment object during your application startup only these environments would be available environment aware interface will take care to create all the predefined required object that means this environment object is available of one of the implementation class of this environment configurable environment one of the implementation class of this environment understood right abstract environment and all this class will take care this class will take care to load the to load the properties file and it will give the object to the environment object that's why environment objects somehow it is available in our container how to get this object using authority auto wire using authority not over here so now see class is is is configured has been been in spring container this would happen during during application start this would happen during application startup this would happen environment class is configured as a bin in string container this would happen during application startup this would happen during application start okay now next one how to get this how to get the value same thing container using it how to inject the bean how to inject get that bean now once you've got environment object what you will do environment dot get property of my properties file environment dot get property of first one environment dot get property of second one okay now you will give like this whenever you will give this it will read automatically the values so it will load the properties file and refer to this properties file with environment environment that's it that means that's it any questions stream here now let's see how to load these values and all will show you practically if i run this my application remaining code is as it is here my example is how to load the properties file based on the neural network that's it instead of now you will get hard code values in our bin now you will get dynamic values now you will get the dynamic values instead of hard code values now you will get dynamic value understanding now if i run this now see domain encoded would be same writing black from properties file ink of power curve properties writing black frame properties file ink of black from the properties file you can understand if i change anything in my properties file go to my properties file if i would change anything properties 5 just to start let's see without disturbing my code now you can run run as java application see now you got it or not just how to load the properties file how to load the properties file means source is the annotation this annotation will load the properties file once it will be in load the properties file then what happened using what the environment class object you can get the values from the get the values from the you know your okay properties file object and give to your application very clear team so this is one way another way is load the properties file using java config value annotation one is this one another one is you have to use directly in your code or the rate value question mark dollar braces black ink dot brand that's it that's it no need to provide any environment no need to provide any environment just you have to give this one you have to give this one your spring will take care your spring will take care this you know authority property annotation just you should have authority property source it is a source whenever you got this this will be this load your properties file into your spring container load your properties file into your spring container once load using authority value once load using authority value using authority value you can get those values from the properties file using authority value you can get those values from the properties file now how this how this value would work who will okay who will recognize how this value will be scan you you have to provide you have to provide [Music] to inject the values from the properties file okay inject the values from the properties file so you you no need to write any code here just you will write this a converted value annotation that annotation will take care how to get the annotation you will take care how to get the values from the properties file automatically how to get the values from the properties file automatically you no need to write any code here understood now go to here but you should remember only one thing whenever you are using the value you should load or the red property source placeholder configure this class is the responsible for to scan your authority value annotation and it will able to you know recognize your other value annotation otherwise we would get an error stream okay see wherever you are going to use other value values understood now you are writing here that's it authority property source is you do to load the properties file into memory otherwise the value annotation is used to get the values from the properties file summary annotation is used load the property files to get the values from the properties file object either using environment object r for the rate value annotation value rotation class will will recognize the rotation got a team or any questions team hope you clear everyone now now we'll see go to here simple go to here runner application context new annotation only because we are using annotation see this is any questions here other value under environment wherever you want you can use this unless your team hope you are clear everyone how to use authority value annotation just wherever you want you can configure in your xml and our java config just don't come to your code and we can use it let's assume that in your spring don't have any properties brand is equal to abcd default value you are trying to avcd means default value you are trying to give here you give default value again your properties file value is there which value will be executed can anyone tell here what is the intention of this default value means yeah default value means hey if i am giving anything means my intention is if any value will be given from external don't take it always take my default value only that's what that intention now can you tell default value which we will be executed our properties file value will be exported yes now properties file value will be executed default properties file will be override with properties file see see always it will go here properties file only if you remove this value properties file comments are if you remove this value let's see now it will take abc is the brand or not if you remove this value now you got abc is the brand if you are not remove what happen always your properties file will be override always your properties file will be overriding default properties default properties always it will execute the priority will give the properties files only now if you see now let's assume that here default also is not there default to not there in our properties file that entry also is not there entry also is comment now still i am trying to access i am trying to get for what that is the value from the properties file now now what is output team now what is output we will get an error error is saying that value is not found this string value is not found so now using other rate value so what is the next value we can set default default value of property keys in other rate value annotation rate value annotation in red value annotation okay here property key default value yeah if the if the property key is not found the property key is not found in in properties file then it will get default value b if both if the if the property key is present in properties file and default value then always always will always will give you property file only property file key value only now see see if the property key is not found in properties file and also is it is not found in properties file and also default value not provided then it will throw an error saying that saying that could not resolve the placeholder illegal argument exception could not resolve the placeholder understood sir that's it same like you can go for xml only same like you can go for xml see go for xml code is same i'm not going to write anything code how to load how you are going to give value xml blocking constructor argument brand name dollar off this one dollar of this one how to load the properties file property placeholder configure class path sample properties whenever this statement it will be executed what happens properties file object will be created properties file object would be created now this properties file object will be hold what all the entries hold for all the interesting understood these entries would be added into where here you can get these values from here cc here if it is okay if it is xml right how to read the xml application context context is equal new class path xml application context run as java application that's it hopefully get it here see got a team frame here so either you can go for xml you can go for java config properties only okay xml auto wire team how this auto wire will be using not using anywhere this bin see that's what i'm what are the component classes all the predefined class all the user different classes you can write component but this class we cannot write in component because it is not written by us that's why if you want to load this what you will do give authority to be in authority property source is easy to load this properties file next what you will do otherwise be in wherever it is required or the right value you should use get the value and you will be injecting wherever you want see it here runner run as java application understood okay okay everyone now shall we discuss what annotation we have youtube till now what are the spring core annotations team one is don't tell by head answer stream i want one by one how to use this screen for we have executed very clearly how to use the spring core team um configuration rate b next one after other rate bin how to replace this bin or the rate component how the component would be happened you should explain very meaningful component will be identified using other rate component scan how to get this component to bins using other it hot over here next one how to inject your xml config with java config for the right import hmm resource how to inject your java config with java config you should go for this next one how to okay scope for declaring as a scope annotation next one heard lazy good next one further it yeah we forgot to conflicts primary we forgot qualifier the next one how the property source next one how they are the rate value annotation understand him how we have explained all this tough team are you played till now okay no till now we are clear team all are clear right now next important to one team before that one of our friend has asked that how to load the primitives how to load the primitives that anyhow we'll tell one example on primitives it would be good how to load the primitives one of our friend was asking it would be good easy only but anyhow we covered that one only right why we should miss that primitivity [Music] yeah yeah all okay everything everything you see how to inject that will show you all first we will take once one simple use case t will take one simple use case new others maven project special case like 0 0 1 spring xml primitive group id is com.streenotech artifact id is this one name is this one this is for primitives and collections so this example i'm taking from here only this only this xml file only i'm taking here because writing typing all this is not good okay recommended i'm taking this sir i'm closing everything now go top now start writing one simple class then simple class may be employee a simple class may be a anything how you want you want a constructor we can go by a constructor you want to get you know um shutter you should go for etcetera it's all okay depends team how you want to go you can go and you will see better will go for one uh one constructor now one set up later we will go for same constructor also you have one class com.cenotek employee employee simple t create employee id private string employee name create string employ city alt sr rda okay source generate to stream okay now here see i want to go for one employee spring test but here is important before going there before going there please try to understand i am removing this also employee com dot employee how to pass the primitivity what is your java b name emp id you need to pass the here value one two three i'm closing the property like that you should give how many values you should give employee id name same this b name your property name should be same this is city that's it now it is xml right java config means easy team how to write your core java that's it nothing is there java oh look xml won't look difficult oh i did not write any added dependent system application context context is equal to new class path because it is xml new class path xml application context give this file name context dot get been off either you will give class name or you will give whatever it earlier we give only id right now we should give class name no problem class employee isd understood this is how to pass the primitives framework framework config java means easy team you can prepare the object inside of the config okay you can prepare the object xml is only how to pass this okay example this suppose your employee objective will have constructor team okay your employee objectively have constructor team if it is constructor now here if it is set property you have names but constructor is somewhat of a different team see let's assume that i don't have this etc the problem with xml see the problem with xml even though you will not write properly if it is java okay it would give a camera if it is okay if it is your xmlc nothing will see if it is java if you are common to this etcetera so it will give unless your team now go for your xml it is earlier this one how to apply comments in your xml this one now you should pause the constructor argument but here you should not you can pass index wise you can pass argument wise here i am passing my first argument is an integer what is the value employee id 1 no need this okay somewhere comment how many are there this second one is string you can pass either type you can pass either index it depends you can pass okay either one if it is xml run as creating bin with employee defined in the class path setting unsatisfied dependency injection constructor with index one of type is stringer where index one it is over here no okay let's see what is dependence injection while creating employee defined in the class path resource setting such as unsatisfied dependence injection argument index of one as string ambiguous constructor argument did you specify the correct beam reference it is asking shall we give instead of type we can give index also index zero index one index two we can pass either type or you can pass name also you can pass them advantage with the constructor see you got the output first index is this or second index is this under third index is this one so you can pass either index you can pass either type you can pass another one type we can pass reference you cannot pass type you can pass what type it is earlier we have given it is an integer only right 0 is an integer now it is a string 2 also is a string maybe ambiguity i i understood yeah yeah i uh here value i should pass this one that is the problem why we should pass this only index is working team employee of definition class path resource unsatisfy expressions to constructor index 1 one of type string do you need to give uncertainty index one is the issue small capital string let's see yeah it was working i gave a small string earlier this is the problem if it is xml if any mistakes are there until okay deploy your work application you cannot see them until okay deploy your you can't see him understood team so we are able to see primitives with construction we are able to see primitives with are we clear team or any questions team do you want to show this as a java also java is easy team java is interesting you can okay object to dot this headset okay we'll get it okay but unfortunately why i could not explain means no one will use this uh okay okay xml that's why we are not focusing on morocco anyhow what is the wrong if you want we'll go for collections also with this same thing here collections means you should go for same with collections also nothing is wrong here how to use your java configurations using collection stream using collections here let's assume that same employee only i have here you should go for string okay or string or whatever it let's assume that either you will go for constructor or you will go for just how to use this one because collections means only it will take as an objective now here now here what happened let's assume that i have here list of strings i have here list of names i have here list i have here list of strings list of names i have everything or you can take only one also for practice you can take only one not a problem we will focus on only one not all how to do this java is easy all tests are rda source generate to stream unfortunately here right your b id is your employee only team how to comment constructor constructor constructor how to comment your xml property name is equal to employee employee already available property name is equal employee id list name is equal to employee id inside of the property you have least right listed you have list is there you have set is there you have map is there everything is there okay depends upon the requirement you should give here value is equal to four four four 555 suppose your employee ids may be a another one private set of string names team actually should give a different names may be in list but ids will not be a duplicate always it would be saved defense team you can go for maps also whatever you want you can go source generate to stream go for here here you should give instead of list here set good if you want to go take one more property take one more property here it is a names names you will use reno you will give tag you will give so you know tag whatever it is done go to here you are injecting them you are injecting later you can inject map also who will stop you another one you should take that one as a map whatever you want to do map also is this map means for what you will get key value both i will show you that also let's see but no one will use this very in rare industry will use that's the reason say i'm not see i got list i got names also suppose you got your one more map now what you will do either you should go for generic map you should go for whatever it you should go for map employee city now you will give employee id and employee city how to go go to here it is one more property this property name your b name should be same remember it is a map it's not a list okay it's not a set it is a map how you will do map go ahead here entry two value will come key key is equal to your employee id one one one value is equal to and close this one like that how many you want you can write no problem done brand new go to here run as java application what is the issue here error creating name with employee defined in the class path nested exception not invalid property employee in city of being class employees city is not writable city property is empty city map map okay what is the error let's see source generate two string run as yes earlier status was not there now you got the map also pair key value key value key value dante i don't know who was asking are you clear team are you clear team thrown all okay got it no got it next question team next to use case very very important yeah till now we have seen how to load the properties file but now next to use cases how to load the properties file based on environment based on environment so you can use that bag also instead of where group of list of the list element is there at the time you can use for bag also sir at the time you can use for bag also okay depends upon the requirement you should go understood sir okay you can use for okay bag also generally bag and all we should go for you know hibernate not for the in spring core in hibernate if you want to map your columns and all you should go but not in spring core collection stream not in spring core collections okay it is also one of the elements of in in spring core if you give class name right it will map if you represent a class as list of objects we can map the list by list our bag elements into the map file that is pure in hibernate not for this spring core team not for for the spring core understood sir so are you clear he can use as a list our bags are so list is always book elements in insertion order is preserved bag is not preserved that's it but no one will use this back most of them will prefer for the list also list only if you want to specify order so you can list without specify order then you should go for back okay what you should go for back i think it came from jdk 1.7 i think if i'm not wrong camera right sir okay now see or no how to load the properties file based on the environment very very important in in real time we will have different environment stream environments are people also called as profiles profiles see in your real time your application developer has developed the application okay your application once you will deploy your application what happened here now the next one i would explain very simple way developer has developed the application commit the code into git repo here we have jenkins is there how the real time use kst developer develop application code double up the application code commit the code into git repo what this jenkins will do whenever you commit the code what this jenkins will do whenever you will commit the code jenkins will read the code from source code git repo generally it will jenkins internally will use maven maven common jdk what it will do compile the code after compile the code okay execute junit very very important unit test cases in our real-time project we will see all execute the unit test cases without unit test cases no project is there after that execute code quality how your code quality is there this answer will see in our project okay okay next one after that execute sonar reports in our project we will see all if all okay build the chart if jar is okay using darker build the image once image is done push the image into docker hub or ec2 in in our aws if that is also is done if that is also is done then deploy image into so many environments we have ninth one if all okay deploy into production i would say in our real time this process is called ci continuous integration i don't want to talk about all this now because it is not related to our core spring core in our real-time project we will explain more this process is called cde so whenever you once your cd right how many environments you have you have development your application will be okay applied into the environment your application will be deployed into test your application will be deployed into uatr i will not use uat until i will use only prod if your application would be deployed into the environment it is dev if it is test it is proud you have database wdb test db on the production db we have devo database we have test database we have broad database if your application will be deployed into dev it will read development properties file to connect to development properties file to connect to dev environment okay environment db generally to connect to to development we need devo db url comma username comma password to connect testdb here wdb is maybe a david out of something under here username is maybe srinu here you have password maybe to connect quotation environment what we will do to connect production what you will do so here db is test db here db is broad understood how in your application you have different environment properties files are there every application you have sample dot properties file it is not any sample iphone the environment dot properties file you have sample iphone create quotation matter very very very very important in your real time those who are working they will know these values dot broad dot properties quality very very important tool so in diving environment properties file loop what happened do back end system configuration is there here new backend system apa app service may be a database they will back end configuration is there if it is test db test to back end configuration is there if it is in production production back end configuration so in your real time and you deploy your application into development when you deploy your application into development it will be it will be connecting it will read the demo properties file get the debug related or dba url username and password it will connecting into devodb if you deploy your application into test environment it will read the test environment properties file it will connect to test2db if you deploy into production it will read the production-based properties file connecting into prodigy remember without this use case no project development is there it doesn't matter it is java.net php sap a b x widget without these profiles without this environment no project is there blindly you should trust me please so trust me please you will see you are coming anybody working here team if anyone is here okay working okay yes have you seen this second never element of profiles check this and uh yeah yes yes so this okay profiles are mandatory team yeah good team yeah now we'll see now my question is how to in real time we will have different environments or profiles how to load the properties file based on the environment i would say in real time we will have different profiles how to identify how to find the environment based properties file sir i have explained here in in earlier okay without spring what happened you know without spring what happened without spring what happened configure profile name in in tomcat you need to configure when without spring configure profile name the bracket like dew test or broad in in okay inside server configuration if it is catalina dot properties file i would give environment is equal to in our code so during application startup all these all the values will be set to jvm how to set to do in jvm system dot set property environment i will show you practically everything devotee like that it will set if it is test right in test server you will give this if it is broad right product server we will give prod in our application our code application code how the application code is there string env is equal system dot get property of enb once it is done string file name is equal what is my file name sample sample iphone plus environment name will come runtime if it is double value will come if it is test okay test value will come if it is broad broad value will come plus dot properties file so at runtime this file name would come to whenever this file name would come what will do you know is same code what is our previous code properties file is equal to new properties file you have to write on the code so you have to read this value from the manual you have to attach this from the manual so to overcome this what spring has given hey this is common this will be set to your jvm instead of you will read all this stuff manually spring has given there is an annotation is called or the rate profile other rate profile other rate profile annotation is used to get the value get the environment value from the jvm which was set during application startup muster company to community but this would be cmt in your project you have environment test comma uat comma production environment or prod how to load how to test how to test how to load environment based properties file so answer is using at the rate of profile annotation neuron meant to basically properties file using other way to profile annotation using other rate of profile annotations using at the rate of profile annotation okay now we'll see how it works and all now we'll see practically using what the rate profile annotations okay next one t okay next one if it is standalone application if it is standalone application if it is standalone application we have to set the environment using using the below options here using system dot set property environment comma do our spring dot profiles dot active is equal to w or test or whatever if it is if it is web application we have to set the environment at server level if it is tomcat every environment we have one server what the tomcat is catalina iphone catalina dot properties file there you should give key value right env is equal to wt if it is j bus i think j was the file is called server.xml file here also you should give vnv is equal to something okay how to get this value how to get the say whenever whenever we set the environment value during application startup it would be set to jbmt it will be set to dv jvmt it is a different one if you use darker if we use darker then set the environment name inside docker file that we'll see later okay whenever we set the environment value during applications startup whenever we set the environment value during applications startup it will set to jvm how to get the values from jvm how to get the values from jvm number one d system dot get property of system dot get property of environment here it is a environment sorry how you are setting here same option is one you can do it option two using profile using other rate profile annotation this will use internally system dot get property annotation only this will use internally system dot get property annotation only this will use internally system dot get property annotation only annotation only understood team defense team how you will be using defense okay now clear okay now we will see practicality how it will be happened now we will see practically how it works let us go understood in this value understood hope you understood this you will go our practice example now you will be able to knock everything see now please concentrate profiles 20 example first how many properties we have devo property qa property and prod okay they go property just i want to show you if the properties file not directly under resource if the properties file under another folder how it happens different way stream you have one is how many number of profiles is equal number of configurations for the data profile demo it is out over here right component scan this is required to read the value from the properties file qa right this one value is equal to see if the if the properties file is available in directly under resource if the properties file is available directly under resource i am using class path colon sample iphone qa dot properties file if the properties file is available not under directly if it is available under properties if it is available under properties then what happens see see here class path remember in real time these kind of use cases will be there at the time you will go to the google instead of struggling a lot if you remember practice when i should go for class path directly if the properties file is available under resource if the properties file is not available under resource you should go for class path properties class sample iphone product dot property square sample life product dot properties file okay now please please try to understand please try to understand what we are explaining okay connects to one team what is next one now the remaining code is same code is i am reading the properties values how you are reading the properties value are you reading the properties value from development are you reading the properties value from test environment are you reading the properties value from qa environment while testing this application developer has the responsibility how to if it is a standalone application how to test two ways one is spring dot profiles dot active is equal to dev another one is system dot set to dot environment is equal to this okay now how to do this one spring dot environment is equal to this how it happens now we'll see practicality now we'll see practically how it happens okay now we'll see one second okay now see how to pass this profile is important if you use this what happened you know you must to use get only if you use this what happened you know whenever you will use this it will it will try to read all this configuration it will try to read configuration it will try to read qa configuration it will try to read but which value it will be match it will be match either do it will be match either qa it will be match either broad the corresponding properties file would be loaded corresponding properties file would be load d understood team corresponding properties file would be loaded t how to do now here c run as we reinstall very very important intros are asking how to pass the environment variable answer is spring sprinkle.profiles dot active this one you will be using legacy one legacy one means compulsory you should get the system dot get property only system dot get property only if you will use primo dot profile start active then other red profile will take care internally it will be using internet book it will be using system dot get property value if the property value will be match which config the corresponding config class it will be executed corresponding config class circuit will be executed constraints are now here see please try to understand go to this properties file qa dev prod go to this runner obviously if i'm giving system dot set property spring profile activity called dev here see if i will run this run as java application it will load do properties of lt between load devo properties if i load system.property qa then what happened during your applications startup during your application startup during this application startup it will try to scan it will try to scan all the config classes it will try to scan all the config classes this where this qa would be match at the rate of profile this qa would be match this here this q a would be match here if this ta would be match here this problem this configuration file would be loaded this configuration file would be loaded this configuration file what is there black ink dot brand black ink dot color look understanding this is what happened now here see now if i run this application run as it will load which properties file qa properties either you should pass from here or you should pass as your jvm arguments either you shouldn't pass here or you shouldn't pass as in jvm argument now here see if i go here to you now run as java application see you've got this production in your real time either you should be run here if you will not do anything what happens see you will get an error see here what error no such bean named writer is defined no such being named writer is defined if you are not configured of anything you you got the error like no such bin is that means now here okay okay what happened it could not be load your properties 5 because of because of this properties file could not load none of the configuration is not matched none of the configuration is not matched if none of the configuration is not matched this component scan also will not be executed this component scan it will not be executed so now what happened and never this component scan if okay for environment it could be executed okay so if none of the component scan will be executed if none of the component scan will be executed so now what happened component scan will not work component scan will not work now here c okay that is the reason at least at least okay should be executed only one then only all the beams okay component scan will be executed now here see either you will be set like this or let's see run as configuration and open environment spring dot profile is equal to the profiles by running see it will load your properties either you should pass from system.set property or you should pass sprinkler.preference.active is equal to devotee are you sure to pass spring does profiles.duty understanding are you clear or any doubts okay now we will see now now another one is another one is the how to optimize do you need three configurations do you need in three configurations no how to combine these three into one configuration see your categories okay profile got annotation is used at class level is used at method level is used at the class level and is used at with the method level t how to use that class level we have already seen how to use direct class level we have already seen now you should go for method level or the rate of profile now you should go for method level see okay instead of you will write all you should write profile property sources placeholder is equal new property sources placeholder configure placeholder dot set location you can give new class path sample iphone devoted properties file it is new class path resource sample iphone qr dot properties file if you see here new class path sample slash properties file class property slash slash this one t because this is available in so in this example it is a directly is available no need understood team if you are using at a class level okay if you are using at a class level a if if for the right profile you'll use at class level then number of of profiles is equal number of profiles is equal to number of configuration classes number of profiles is equal number of configuration classes if if furtherate profile will use at method level then then number of then one configuration class then one configuration class which will have which will have which will have number of methods then one configuration class which will have then one configuration class which contains number of profiles is equal number of methods number of profiles is equal number of methods each method each method will take care to load to load each profile properties file each profile properties understood team okay or not now you will see other profile you can use at class level or you can use at method level if you use at class level number of environments is equal i mean number of profiles is equal to that many classes config classes we should use if you use that if you use that method level then what happened you need to use all in one single config class you should write the code how to load the properties file properties sources placeholder config is equal to new property places folder configure placeholder dot set location new class path resource it will be done if it is qa it will be done qa if it is production it will be done for the broad team see i will show you practically here how to run the application here either you can set from the standalone application you can set from the here run as java application it will load the qa properties file between load the qa properties file or if none of the also is there let's see component scans should work will not get any error but value will not coming from the properties file if the value will not come the properties file you will get an error no property found okay something you will get on error team see run as java application see writing with you are getting these values will be replaced these values will be replaced instead of you are getting error team now if you see here whatever spring configuration will do if you are not getting anything these values will be replacing with as a name this value will be replacing with as a color team understood that's why you have to pass the okay never mind profiles either following like this are run as configuration environment new spring dot profiles dot active devotee that's it okay team now if you run the application now oh already done no you got it this is what team how to load the properties file based on the environment till now we have user properties file environment now you can go for a properties file using xml using xml using xml c i have different xml it is like equivalent to dev properties file i have qa xml same code or spring framework dot b dot factory dot config dot this one i am loading qa properties file similarly i am loading production but how to import one xml to another xml i told okay there is element inside of xml is called import i'm importing debug configuration i'm importing qa i'm importing prod i'm importing all team here i'm importing everything here here bin id this is same but how to import one xml into another xml how to import one java config into another java config okay yesterday we have seen attribute import similarly if it is xml how you are importing one xml to another xml using import to tag so that all would be available here now you will pass the environment how to pass the environment same code but instead of annotation here okay xml class path that's it if it is dev if it is qa qa if it is prod understood team are you clear or not or any questions team now till now we have seen how to load this properties file using standalone now we will go for if i deployed application into my tomcat spring of profiles with the spring of profiles with if i want to deploy application into my tomcat how to deploy your application into tomcat have you seen anywhere your standalone method here have you seen anywhere your standalone method team here standalone means your main method class is there here please try to understand here main method class is there here no i am using spring config i am using spring conflicting here i am using web.xml if you are using java config in web.xml please try to understand if you are using java config in web.xml see in our real time most of the applications spring is core model only this core module will be there is no projects is called only core model team core module will be used for to develop a publication to develop a rest api store develop any distributed applications there is no real time project is only sprinkler what is the job of the sprinkler sprinkler will provide the objects objects instead of developer will create the objects sprinkle will provide everything to you for as per your needs here we are providing context to load and listen up this has the responsible bootstrap your root application context using context listener how to do control shift to t see this will also internally will use web application initializer this class has the responsibility to load your f.xml user use or not to load it is replacement of your account.xml it is a replacement of your accept.xml it will map your slash through to your tomcat everything cd during your application startup only you it will you know application startup only this will be responsible to create the servlet context object that means it will this class has the responsible to load this okay.xml and you know after loading this f dot xml it will identify it will create your spring container object using this once that container is creating it is trying to load all these classes based on the profile how to configure the profile teams if it is tomcat right go to if your is tomcat right in our project wherever tomcat is there how to load the environment properties file from the tomcat go to here go to here softwares apache tomcat if it is j bus j bus also config catalina dot properties file it is spring application right you should use spring application dot do you are proud dot profiles dot active is equal to prod now if i build my application run as can be installed now refresh during your application startup what logs will come to you here it will verify your spring config is loaded writer dot write to method will be executed here t now please concentrate here what is there here prod in your code you have product properties file yes this one would be loaded during startup only we will get all the logs and all where can we see the logs here during startup only because you are calling during your startup you will get it everything during startup in logs it will be printed like this writing with the qa properties let's see writing with a property hey startup.sh startup.bin let me check first did you deploy your application into your web apps copy now see loaded broad spring configuration loaded broad spring configuration writing work with the black prod ink of parker writing with the black prodigal parker broad brand understood if you give here now qe means here you are giving means i told clearly if it is tomcat you should give like this here if it is tomcat here you should give spring dot profiles dot acting if it is darker you should give here also whenever you will give this one right now what happened how to get other profiles will will try to read the value from the jvm during your application startup all the properties will be set to jvm if any property you want android profile will get this spring dot profile value from the jvm whatever value is there from jvm your other profile will take it and it will start it will find is there any profile classes or profile method is available if it is available corresponding properties file would be loaded okay if it is clear right now let's see are we clear team are we clear or not okay everyone remaining questions team many questions team all okay everyone good now see team what annotations we have practice it till now we have implemented one is one is what is first one first one rate configuration second one are there you have to be in good way after configuration bean only will come third one each you can remember team yeah so instead of b you should give as a component fourth one for the rate component scan good way how to scan these component classes using other components and fifth one right auto wire auto wire way how to get the beans of this component sixth one how to inject your your xml into java config seventh one address import to one java config would be imported to another java config after that how to resolve the ambiguity after that to resolve the ambiguity using qualifier and all next one we need to practice okay examples on scope understood yeah scope means during startup only beans are loaded if you don't want startup you should go for lazy next one next one thing team what is next one anyone before profile what we have discussed before value what we have discussed yeah see that's what you should not buy here the rate property source is u02 to load the properties file once the properties file will be loaded then only we should get this value once you have a value will be loaded how to load the properties file based on the environment now you should go for authority profile you should not buy here team the based on the use case we should remember all 14 next one team required to make generally when you should go for constructor and shutter injection if the dependency is mandatory you should go for a constructor because the dependency is optional you should go sutter injection to make sector injection also mandatory to make shutter injection also mandatory we should go for other rate required on top of some saturn injection on top of saturn methods you should declare so that that so that for setter dependency also for sector also dependency was mandatory also dependency was mandatory mandatory team understood team we have discussed around dominating 15 annotations we have discussed any questions team here any question stream here another two annotations are there these two are java annotations is nothing but it's a bean although it named is nothing but either it's a bean or are there to be our red component otherwise inject is nothing but auto wire these two are java annotations these two are java guys all are spring but these two are only java guys has implemented this understood either you should go for b or you should go for name or you should go for other component any questions team till 15 annotations any questions team we have discussed till now 15 any questions team any questions tim hope okay everyone we are clear all okay now what are the examples okay we have a discussion till now just two for examples one is one is constructor injection using xml now two is shutter injection using xml config next one team constructor injection using java config shutter injection using java config 51 team what is fifth one team fifth one is import import xml config with java config sixth one import java config java config seventh one we have seen integrate xml config comma java how to resolve the ambiguity using address pro using a thread primary command using a thread primary comma thread qualifier how to resolve the ambiguity using a thread primary comma the right qualifier team connects to one team okay what is next one scope stream we have discussed about scopes scopes we have discussed both example singleton prototype scopes in the bracket using java config using auto wire using xml team okay next to one team immediately we have started how to load the properties files no no lazy annotations are the rate lazy annotation examples next one primitives primitives comma collections examples next one how to load properties files using xml how to load properties file using java config how to load properties file auto wire next one is profiles using class level profiles using method level profiles using server level using xml and using xml and java underscore team this is what we have discussed until now any question once again hope nothing is opposite of surprising team here hope all our good team now okay next to one team what is the next topic any questions stream till now any questions team no clear no good next example team see i will show you this annotation stop annotation see same team same as previous component scan and all wherever component is there or the right name wherever component is there or the right name wherever component is there or that name so if you observe these are the our j2ee annotations these are our annotations these are not our spring annotations these are the j2e annotations not the spring annotations look at him wherever auto wire is there you can use this inject you can inject the beans using constructor you can inject the beans using xml sorry setter you can inject the bean using field level remember these annotations are available in j2ee not a spring framework not a spring framework understood now here spring core is okay here okay no runner if you see here just i'm declaring whether this beans are coming or not i think you should go ahead with backhand dummy data only only how to use authority injector and other rate how to use at rate inject under it named these two are given by whole spring team now if i run the application same stuff known as java configuration cd better with the bragging of