Spring Framework Tutorial | Full Course

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome back everyone my name is Evans Betty and in this video we'll talk about spring framework now Spring Framework is one of the best framework available for Java now why do we need it not think about this when you are working on Java technology maybe a software development or a web development or maybe the enterprise development now depend upon what you are working on we have a module available in spring example let's say one of the common issue which we face is dependencies right so one object needs some other object so Spring says hey you don't have to worry about that I will give you feature of IOC again what is that what is dependency injection what is IOC we'll talk about that in the video but it provides IOC and dependency injection what if you want to work on web framework in the moment you save web of there's one thing very famous there which is MVC and spring has a module for it which is spring MVC what if you want to connect to database we have a separate module for that so in this course we are going to focus on the first part which is spring dependency injection we'll be having a separate course on NBC and then the rest part but here we are focusing only on spring dependency injection or you can say Spring Framework with core right there's more important thing you have to understand which is maven because when you build spring projects you will be using maven as a build tool so so first we will be learning about dependency injection then we'll go from maven and then we'll implement spring IOC and then we will implement spring dependency injection so I hope you will enjoy the code so he that like button and do subscribe because we'll be uploading a lot of programming videos on this channel and in this video we'll talk about dependency injection now if you are working on a project let's say if you are working on some advanced project of course you will be using some design patterns and one of the design patterns which we come across is dependency injection doesn't matter which language we use maybe Java c-sharp PHP we have this concept there but what is so important so in fact we have this questions right what is dependency injection and why everyone want to use it in fact if you talk to some expert in industry people who are working from a long time they use this concept by default or not for them it's like a normal thing but for new developers it's a new thing right for them you need to understand how what is dependency injection and why to use it now how to use it that we'll see in the practical but then how do you why do you use it that's a question now think about this now when you say dependency in in software programming software what we do is we build good right we build objects if you are working with object-oriented programming so we build objects right and those objects are dependent some on some other objects so we create this object graph right so one object is depend upon some other object and that object depends on one object to give you an example in real life let's say if you want to buy a laptop if you want to build a laptop let's say you are a laptop manufacturer now in this case in laptop you have certain certain parts right we have a ram you have a hard drive you have a screen and of course what makes a good laptop is good parts right example if you buy a laptop from any company the same company they have a low range laptop and a high range laptop what changes is the type of hard drive we use the type of RAM we use so of course all these components are not built by the same company so let's say if you buy a Apple machine of course Apple will not be building all the step by themselves they will be buying it from some other companies maybe the screen of MacBook is from Samsung maybe the hard drive is from Itachi maybe the RAM is from Sanders so all these different company they they help they help one company to build a project or build a machine now the same way if you want to build up object and if you want to let's say if you have an object and that option is dependent on some other object in this case you will not be building all this stuff by yourself of course you will be having classes for that right so in Java what we do is we first rate class and then we create object now to get an example let's say we have a class here which is class let's a laptop and in the inside class laptop we need a object of hard driving in object of RAM now how many do it of course you will be saying new right and when you say hard drive of course you need a point class right and that lets say we have hitachi hard drive now let's say if you build a MacBook with Hitachi hard drive what if in future you want to change it because we want to achieve this concept of loose coupling right I am sure you know about this concept of tight coupling and loose coupling that's what we have learned in software engineering when you say loose coupling it means one optic is not totally depend upon another object it may get replace example if you have Itachi hard drive in future you might want to use Samsung hard drive it should pass it should be possible right and that's why we use this concept of abstraction what we do is we say okay for each class let's say Hitachi hard drive let's create abstract class or interface colors hard drive so when you instantiate it it will be something like hard drive ABC or hard drive obj equal to new Hitachi hard drive so that in future you can change it from Hitachi hard drive to Samsung hard drive it should be that easy but there's a question here we are hard coding it right we are saying hey we I'm I'm going for a new guitar hard drive and that's a bad thing because the moment you say hard coding the moment you say new you are going for tight coupling that's that's what we don't want so we want someone else to give me those dependency or that's important term here so the laptop object is dependent on the hard drive object that's a dependency so we want to inject the hard drive object inside this inside this laptop class and the way you can do that is by using some service which will be external service they will inject the dependency okay how it is possible so we have this concept of dependency Injection containers now they are responsible to create a object for you of course the object has to be created so they are responsible to create the object for you and then they will be injecting in your plus okay but wait to mention that I want to inject and how if you create the object and that's where we have to do configuration now there are different ways of configuration configuring it example if you are using Java in Java we have Spring Framework and in Spring Framework we need to do so a lot of configuration earlier days we used to work with Spring Framework ways to configure everything using XML okay so that's that's that's how you can configure so create XML file and in the example file you can mention hey if someone is asking for a hard drive give this object ok now when you say XML it means you can edit XML in future right so that is not a tight coupled ok but still as a job Obama you don't want to focus more on XML and that's where in we have spring boot in Java using which what you can do is just we will be having some class as Hitachi hard drive right or Samsung hard drive so on top of these classes you will simply write add component that's it ok so you simply like add component which makes them dependent which makes them a component of a spring framework which will be generated as per requirement ok so those those object are ready with Spring Framework but what about this plus how will this mention that you want this object so on top of your hard drive what you can say is you can say Auto wire ok let's say your Spring Framework says or your spring boot with the help of Spring Framework says ok here someone is asking for hard drive ok so this class needs a hard drive and I do have a component there so I can connect them like that some types of auto wired and just imagine so beautiful they are getting connected again the implementation you will say later but this is this is the main idea behind dependency injection right but why we need this is it only because of tight coupling the answer is yes we don't want to achieve tight coupling we want loose coupling plus there is one more important factor which is testing you need to test yourself right now we always test our software as a whole but sometimes we need to not sometimes always we should all we should also be testing your each component each unit now the thing is let's say if you want to test a laptop and laughed when you said when you test a laptop you should also test the hard drive but don't you think when you buy a hard drive like when Apple bought hard drive from Samsung they must have tested that hard drive right why you need to test the hard drive again and again so what you want is when you are testing a laptop you want to separate the hard drive right so in fact in Jogja world what you can think is you have a class and that class is working with a database object now you are testing this class right you don't want to test the database object so you can create a mock object of this of this class only if they are loosely coupled so if you have a mock object you can easily test this class without affecting your database okay and to achieve that feature you have to make sure that your software is loosely coupled and that's why we have so many words right we have loosely coupled we have dependency injection so so that's that's so amazing about a pencil injection you just need to implement it so that you can test it better you can maintain it better and how it exactly works that we'll see in the practical video today when we talk about maven hold on we have already heard about that in one of the video right so if you have seen my last video I've talked about Madden but then after that I have talked about different technologies like hybrid night spring and then you are going to start with rest now so I want to make sure that you know this topic thoroughly so let's start with it so Madden is basically a build tool and it is under a license of Apache and if you go to mem repository there lots of libraries available but hold on why do we even need a man maven thing so basically what happens you know when you walk when you want to work with a new project I mean when you want to get a project of course you need some third-party libraries right example let's say if you want to create a project where you want to work with mask you'll so if you get a java application if you want to connect with mask you all what you need is my SQL connector so that's one of the dependency you need so you need a mask you'll connector the second thing is this if you also walking bit spring so when you work with spring and we see you need lots of dependencies right in fact when you talk about spring MVC or we need minimum minimum we need minimum at least 10 or 12 depend on libraries what you say or Java files for hibernate really require 10 or life 11 library system imagine if you are working with all these frameworks you have to download all this dependency by yourself and that's a difficult thing right so if it wanted to unload everything by yourself that's not a good thing okay but if you do that you will say ok I'm a programmer I will download everything from the internet that's fine the thing is when you do it by yourself when you download all the video by yourself the problem is not video theta the dependency by yourself the problem is in future if you want to update it so let's say from spring for now you have to go for spring 5 what you have to do is you have to again go to spur you have to again go to spring spring repository and if you download those dependencies and trust me it's a pain because we first of all first of all you have to download the download dependency second you have to make sure that you the dependency which you have downloaded for spring is matching with the hibernate dependency right and to solve this problem we have a mement repository so maybe says hey people don't worry again mam has lots of advantages like we have different goals to achieve we can compile it we can deploy using Navin but here the important point for me is getting those jar files right because when you work on a project those jar files are very very important to work with now question arises how do you get those jar files it's very easy actually you have to go to manage repository and say hey man repository I want spring dependencies same ever in repository I want how many dependencies and I will say ok so these are your spring dependencies decide you haven't decided I want dependencies and you got it ok we feel if you if you're thinking about what is dependency to jar files right so if you need so in Java us to work with some technologists you need those I call it dependencies so Maddon will give you those jar or library dependency to you but hold on it's mavin a super man to do all those things or super for me to do all those things not exactly so in navin you have to specify so whenever you get a project basically we have to remember some terms here now going to Sendai when you have to remember this term so first first first of all the project so what is project basically everything whatever you Kate input is in mavin is basically a project now in that project the most important file is this file which is p o m dot xml now this is the files whether you variable mention everything so if you need hibernate just mention that hey I want hibernate not in this way but we have different syntax ok so we have to mention a I need I need spring again not in this way we have a different way of doing that but this is the file where you have to mention to hibernate hey I want all to mavin hey I want these dependencies the second the second thing you have to remember is something called as artifact ID or let's let's go for group ID first so this next thing we need is group ID how it is go party see there are different type of project which build by different people right or different companies so if I am welding five projects I want to make sure that each of my project is unique throughout the world ok now how do we make sure that you are you having a project which is unique for the world so have to make sure that the artifact ID which you are using is unique let's see if I if I give our artifact ideas demo visit UNIX or the world not exactly right anyone can create a project with demo name how about if I create a project name as ABC and ABC one two three four ABC one two three four the big name there's a chance that it meet that the name might repeat right and that's why what we do is we combine the group ID and the artifact ID so artifact ID will represent your project name and group ID will define your package example let's say if I'm making a project and I'm the I'm working for the disco so it would be tech Tom telesco that's my group ID so all the project which we build will be a part of come to the disco and the project is let's a demo so now we have comm dr. disco demo and of course we have to make sure that we are not getting demo project once again right so that's your artefact ID which is your demo and your group ID is that comdata disco again you can use the same thing as your package name you can say compact it is for our demo dot grabber that's your package name right so you have two little blue these thumbs and your your manage will become very easy to you so okay so now how do you mention in mavin that we want dependencies so you can see it's a very simple palm file where you have depends it to add dependencies tab now if you want a spring jump on it's very easy just go to the official website of spring odd okay so we can go to office website of spring you can you can copy that code but then it's not going to individual website like go to spring website go to hibernate website one in also do is you can just go to an MB and repository which is a central repository for all the jar files just go there and search for spring it will give you a code just go to your palm file and paste and you will get your project Bank I mean you will get all your dependencies that's awesome right and trust me it works like a magic now question arise if you don't have that jar file in your machine that means it is coming from the internet right so whenever you work with man when you have to make sure that you are connected you connected with the Internet and that's what the problem starts every time you create a project you have to make sure that you're connected with the Internet okay that's not the case what happens is when you are using spring dependency for the first time let's say if you are using spring 4.2 3.8 for the first time it will get downloaded from the remote repository so mavin has a remote repository from where you get all the jar files but it also has a local repository so in your machine you will be having a local repository so every time you ask for a dependency now it will first search for local repository if it is not that it will go to a more depository now next time when you search for it you already have it in local the positive right so it will it will increase your performance or you can say it is a time it takes to download those dependencies so that's awesome thing right so we can use mavin to build our project and we can get all the Java files again we have not talked about everything in ramen is a very big topic is it this video is important for you because if you want to learn about spring of course all the project which you will build in spring maybe we will be based on lemon okay now mavin is not the only way to do that we also have a way which is called as Gradle like if you have ever worked on Android we use Gradle there but then for web projects for Java projects most of as we use method ok we can also use get it in Java as well okay so yeah that's it in this video we'll talk about the practical implementation of mavin so in the last video we have talked about the theory of mavin so just to give a quick recap what is mavin so mavin is a build tool so let's say you want to create a new project in which you want a project structure you want something that will compile your files you want something which will test your application and you want something which will give you all the required libraries so the main problem arise when you have when you want to create an application using spring so let's say you want to build an application in which you have to use spring maybe you have to use hibernate for those spring and hibernate we have we require some dependencies which is libraries so you can to work with hibernate you require lab is to work with spring or starts you require levels now to to get all the saplings you have to go to a website which is let's say spring dot IO and you can download your degrees here now that's very easy right but the problem is so when you go to go to this spring so where you will get all the Java files recovered so if you click on this project you can see spring provides lots of frameworks so we'll select Spring Framework here and if I go to Spring Framework I have option of download T jar files and we have download link no we don't have any download link so you can see we cannot download the die base from here the problem is even if you can download you know if spring provides the feature to download this that is if you don't know about spring it's ok we are just using spring in our application because I'm making this video so that I can work on spring in future on this in the seed series of tutorial but people who are not concerned about spring they are only watching this video just to learn mavin so it's ok you might be implementing spring using maven you might be implementing hi but not using my oven so everything is almost same you just have to deal with this part ok so it doesn't matter if you're walking one spring or not so come back to this spring parts ok when you talk about this download file so even if you can no disappearing libraries maybe in future you're downloading the current version which is for maybe in future you have five so again you haven't established by yourself right so as a developer you have download all the reviews what if you can just mention someone an application that I want split I will use and someone else you know but not you maybe someone else a software in your system which will download all the required libraries and that someone is mavin what you have to do is you just have to use this type of text in your application automatically to download all the required jar jar files for spring not one all that's the advantage so how to use this part in your application so we don't have to create a normal web app in or --ml codes our application we have to create a map in application so for that we have to click on new window by default when you create an application you always choose Java project but this time we'll choose my haven't project because we want to create a maven project we'll click on next it is asking for the default work location and I will keep it as default which is checked if you click on next there are lots of options so you can see a term here which is archetype so as we have discussed in the last video so archetype is just a template of your project so then let's say you want to build a core java application so you have to choose archetype you have to create our web application so you have to choose a different talk type so you can see if you want to create a web application you have to choose this archetype which is mavin - archetype - web app in this I'll be using a coach our application so I will be choosing this one which is mapping archetype quick start so quick start will give you the coach of application so if you think we don't we have only this number of options and the answer is no so you can also click on all catalog so as soon as I click on all catalog you can see something is happening here we just tried trying to download all the archetypes available in the remote server okay so maven is a network already appliqu network ready framework so whenever you walk with maven you have to make sure you have a proper internet connection so I will not yes so you can see I we have lots of Ark types available so if you want to work with App Engine if you want to work with AWS for everything we have a different octave available so you can see this is App Engine we have got soft of type Co you know I don't know all the subtypes doesn't matter so if you have to choose the next one which is internal so this is internal archetypes which may choose now have an archetype we start and then we will click on next so you can see we have a group ID so basically group ID is your package name so we will say group IDs just a comm dot nubbin and we'll make this application name as telescope ok that's my application name so group ID is your package name and then this artifact ID is your project name so in fact the package name combines the group ID is a confirmation of group ID at artifact ID which is gamma MnDOT telescope and then that's it so we'll click on finish so click on finish it will create a project ok and then you can see if you expand this mavin dependencies you already have a jar file here ok now from where you're getting this jar file so this dolphin is coming from the remote server but hold out every time you create a new application the Javas will be coming for node remote application since already have created a project in which I have J unit so what your mavin will do is it will create two depositories one will be the mote repository second will be the local repository the remote repository will be on remote server and the local repository will be on your machine now how to check ways that you won't report tree so it's it is giving the path so it is users knowing it's my user account name and then the folder name is dot m2 which is by default hidden folder in m2 folder we have with a positive and it's positive we have the type of library which is is the problem that is J unit and then J unit and the version is to the point 8.1 ok so just to confirm let's see where it is file s so I would open my terminal so if you are using Mac or UNIX so you can just open your terminal and type LS and you can see we don't have any folder called as dot - when you say dot M - so what we can do is we'll say clear and we say LS v 1 a so as soon as you say LS - a you can say you can see there is a foldable dot M - so again that's a clear we'll say LS not LS will say city dot and - so yeah so currently I'm to m2 folder and we say LS just to list the folders I have a repository folder let me go to the posit riche Alice I have all this folder Co so you can see there is a Jain unit folder so it's a silly J unit LS I get a gigantic folder so say j LS and then we can you can see we have two jar files one is three point eight point one and then we have three point eight point two so maybe some you know maybe last time I have created a project using the latest Java file which is three point eight point two but will not well have been should I which version I want to use and which alpha as I need so in this first structure you can see there is something called as p om dot xml so the main part of mavin this this file is P over m dot XML so you can see all your configuration in this file which is Bo m dot XML now also formed or XML now in this you have to mention something you have to mention the glue PI D I can you to Detroit all this thing when you create a project you will get everything so you will get a group ID you will get the artifact ID and the packaging time so if you're creating a coach or application it will be a jar file if you are creating a web application it'll be eval file next this then this is very important for you this is called a dependencies now whenever you put in an application in the application if you want to use any third party API so you have to mention that dependency here so if you want to use RJ unit in your project so you have to mention this dependency since you are mentioning group ideas j-unit artifact ideas j-unit and that version 0.8.1 that's why you are getting this one how about let me do some experiment let me write three point eight point two so against it says building a workspace and then it is it has changed three point eight point two because it was already in my local to global local repository let me know something I don't know you even that exists three point eight point zero so if I say you can say it takes some time to build and also if we don't have anything called as a point eight point one or eight point zero maybe just wild try I've not done this experiment before so I might get another so I'm getting in these others so we don't have current available three point seven point one we have three point eight point one has three point eight point two okay so that's how we have to create this three power this generate here now the next part is you have to when you expand this folder SRC so you can see what this is all so let's point this SRC so in essence if we have two folders one is main and test so if you expand main you have Java so I hope you remember the package name which is calm dot no mean dot telesco if I expand the net score I have a file which is app dot Java and by default you can see we have something called as HelloWorld awesome right so you talked write it like this quite nice you will be getting the basic code by itself and then this is a file structure so the advantage of using happen here is you get a project structure you also get all the required dependencies but hold on I want spring lobby is now how to get those libraries x time easy just open your palm file so you can see we have a dependencies tag here and that in that dependencies we have a dependency which is generate how about if I add one more dependency now how to do that just go to spring website and just copy this dependency as we have done we have navigated to this part in the subtle tutorial so just copy the dependency go to eclipse and paste and see the beauty of my oven now so you get all the required Java files right and it is everything is coming from the remote server I can since I have done this application before I am getting all this from the local repository so if your do anything for the first time it will download everything from the remote repository it will take some it may take some time from 20 seconds to 1 minute depend upon your time speed or maybe 10 seconds if you are using a high-speed Internet since I already have this into my local repository it doesn't take much time simple so this is how you have to create a simple Mamun application so the next part will be talking about how to implement spraying and how to achieve dependency injection so in the last video we have talked about mavin so we have created a project or the power structure using mavin in which I have mentioned or pom file in which we are mentioning the dependency for spring and then we are we have we've got this app file now what we'll be doing is we'll be not using this app dot Java so I hope you have seen my a theory you have seen my video which is spring theory which is the first video of this playlist and that we have talked about why we wire spring so just to give a quick recap why we require spring framework so spring provide multiple features so spring we can use playing with web we can use pre you spring for a dependency injection so what is basically dependency injection is so let's say you want to create a car in that car you have lots of parts you have tire you have engine so instead of creating so so instead of creating everything by yourself at runtime what you can do is whatever dependency you need you can ask someone else to give you those dependencies so that in future if you exchange your dependencies you don't have changed your code now what what what I mean by all this thing you will understand when I start with the code so in you should it will but you will find it very difficult or maybe confusing maybe am not maybe I was not able to explain it clearly for it clear to you how what is magic what is like a spring is but I'm sure if you if you see some of the videos in you know in the further tutorials I you will get some idea about it start creating applications start working on it and you will get the clear the idea i will also suggest you to read a book of spring with this tutorial so that this video will give you the basic idea of spraying not the detail or what you say in detail description so I'm just teaching you spring just to make sure that you will you can build an application but to understand this concept you know purely you have to read some book I will suggest there is a book from rod Johnson a soft copy of this but you can find it on spraying dot IO which is the official website of spring which is amazing book noida but you know it to buy any hard copy book from maybe online stores you can just use that reference so let me split this let me start with the actual work okay just be with me you will get the idea of why why we have to use brain so let's start with building a car so what I will do is in my telescope package let me create a new class okay and in your class okay like package okay no other and I need a glass okay and package will become dot Java dot telescope and the class they will Appendix A I want to build a car okay and finish now just to build this car what we need is this car will have some features let's say we'll say this with this car we can drive this car and this will say ok I might use some hindi words here because I love this language Hindi so what I will do is just drive I will say Childre he have its implements its rights it's working so our children I was to be sound cheesy so now let's open my app can you say this third somewhere what's wrong with my package I can't see car here I can see you I know I should run jump it's okay you know that part okay so in that app what we can do is we could be afraid to create object of that car so we say car God equal to new car so this car is the class name and this car here this is the what you say reference and we can simply say car dot right simple and let me just run this so if I run this app so I can see it will show me the output as shall I that means it's working right so you can see I'd say it's bribe and it says children let me do some modification Oh the problem here is when you talk about card let's say in future I don't want to use a card I want to use maybe bike or maybe I want to use I don't know what maybe some others other other vehicle so the problem is if I change if I were to make a different class here let me let me create one more class and we'll name this class as bike ok the problem is in this bike also will be having a method for s public void we don't drive be right by right so let me use like and French so it I will print here again in progress thanks running so in that in in the car class I have child Wahaha and in bike we have Barajas so I just want to yeah doesn't matter and then just to make it similar we'll drive a bike this time I know I know it's it we should drive it but you know just to say what you say sake of example then it will make it drive maybe la bike lover will hit me up to this video but it's ok yeah so what I want so in future you find a change so I have to change both wire to change this also I have to say this is bike and I have to change this to bike and then we can say well not say this is car we'll say this is just to make it simple I will say this is obj ok and ok so we can say oh we should have drive and have knife I done this I will get bar graph which is by class right the problem is if I update my classes I have to change the source code why I need to change the source code I want to make it I want to make it in I want to run it such a way that it will not depend upon the class God or class bike so this main function here or this object should be independent of this of this classes here now how to remove this dependencies so we have to use a cept op dependency injection so before implementing the dependency injection let me remove this bike here so we have two dependencies we have dependency on right side and we have dependency on left side what I'm saying yeah that's right yeah so we have on dependency on left and right so what we can do is maybe let's create interface so if I create our interface the advantage will be both bike and car they aren't vehicle right so the advantage will be in this vehicle I will say a public void dry which is just declared and since we are defining our interface we don't have to use public because by default all the methods in interface are public right and then we'll this will say this car implements this power implements vehicle and even this bike implements implements vehicle and that's why I described okay just just to make sure we drive a vehicle and then it's not bike what what if if I keep it as vehicle but the advantage is even if I you want to change from bike to card I have to change only the right part which is from God from bike to car or from car to buy it so we have to change only one thing but why to change that one thing also we want to make it you know such a way that we don't have to change that lock side part and you just to do that what we need is we have to use way to use Spring Framework so what we'll do is we'll we'll ask we'll say I don't want to say new car I want to say get me up being simple get me a beam and that beam should be a way call doesn't matter which vehicle is available I want a vehicle so let's say I want to go to a college or I want to go to office I will say give me a vehicle that's it so if I have a car available I will get a car if I have a bike available I will get a bike so I will say get been vehicle but hold on what is get beam now a pin is a method which belongs to we can we can you can use bed get beam from two interfaces the first interface if use is built factory now the second interface you can use is application context so either you can use bit factory or you can use application context both this belongs to Spring Framework so you're going to use pin factory you have to input a package and you can see the packages comp dot Spring Framework dot beans dot factory if I'm to work with application context the package is the package it's not working it should be should work I just because of the end of things so this application context so it also belongs to what a spring framework now which is better so if you're creating a small application you can use bin factory but if you are creating a enterprise level application or web application you should always go for application context so application context is a superset of bin factory so whatever features provided by bin factories also provided by application context so why not application context so in this application we'll be using an application context and we'll name the object as fun text itself will say next or new now the problem is application context with an interface so to implement that we have to use class class spot class path XML application context ok now if your question is how will I remember all those classes the problem is when I started learning Spring Framework so even at that time I was not doing how to what are the class name our interface name is once you start making applications you will get in a habit of remember in all these class names ok so that's ok you know you should you have to use some book or therefore some book but after having hands-on experience you can just you know just type all those things and this yeah so that's it and then we have to say context dot get bean and then it will give you a turn but this problem this gateway will give you the object so you can see we are getting an error so it says cannot convert from object to vehicle so gate bid will give you object of object right so we have to typecast earth to vehicle so we have to say it will give me the object of vehicle okay that's it it's working so I think everything is perfect you are asking application context to give you the gate beam of vehicle I think it should work let's try a sensor on this application it says illegal State exception big factory not initialized on already call refresh and now as they around the problem is whenever you work with application context off anyway you walk with class path application XML application context it says ok I will give you the object of vehicle but tell me what is this vehicle this is not a class thing this is just a keyword right how would I know which class it is just you what because vehicle itself is interface we go and you can only create instance of a class right and that is your bike or car so you have to define it somewhere you have to mention whenever I ask for a vehicle I need a car instance so to do that we have to create a XML file ok in an XML file you can mention which object you need whenever you call a vehicle ok now how to create a XML file how to complete this whole application that will say in the next part of the video so now let's see how to create an XML file by the way from where we can just read the data what we want so to create that file just go to your package within your SRC and just say new and we need to create our XML file so it's a XML and then we'll choose XML file we said next and it will leave this name this as spring dot XML we can give any name doesn't matter and then we'll be using some tags here so the main time we have to use is beans tag okay and everything will be in this being stag so the beans tag will be the root tag of your XML now since we need a bean so you can see we are asking for a bean okay so way to define this being here so to define this be in use we have to say beans admission ID equal to now that ID should be the idea I'm mentioning here so if you are mentioning vehicle so it should be very clear so we have vehicle okay and then we have to also mention the class so from which class you want to create that so we have to create from comm torch I've been dot that is co and then we have to close the bean tag and that's it so once you do this you will get your the your bin file or you will you're getting your object of vehicle well then we have we have not mentioned the class names of it will mention the class the mass car ok Dexter plus now you have to mention that file some weather so in this application context it does double quotes you have to mention it is spring dot XML so that whenever you call for when you we could object of this context it will go to the spring dot XML file just to load all the config configuration so now you know whenever you call for the vehicle you will get a car amazing right and but there is one problem whenever you work with XML XML always go for the user-defined tags right or pre default what you say custom tags and this custom tags needs our definition now you cannot try anti granule Yuki you can just loop out of it even though you use a tag you have to make sure that tag has a definition now from very weak at the definition so you can look for different projects or you can just go to spring website for the definition I have already have a differential with me and this is a definition I have so just copy this definition and paste it here so you can get this from you can just google it or you can just you you can go to the spring website and you can download this definition okay so this is the definition for the beans tag okay this one since I'm walking with the spring 4.0 version so I'm using four points you know SEC you are walking with three points you libel is you have to mention 3.0 444 is the latest what do you say they just watch it for spring here and let's run this now so if I run this boom so you can getting Childre and that's the magic right in this I'm not mentioning anything I'm not mentioning car I'm not mentioning bike it is totally independent I am injecting those objects from external location so you can see if I if I change this to bike okay and if I run this and then I'm getting bar graph which is for bike right but you will say what's a big deal if only for if I want bike or car I have to change something right but hold on in the earlier version we were changing the source code of Java so anybody to see change the source code for Java you have to recap on your files this time we are changing the XML file we don't have to recompile we just have to say save and that's the advantage of using Spring Framework okay so that's the basic idea of how to use spring code how to achieve dependency injection if the further videos will talk about how to set different properties how to use multiple objects and object inside an object so how to do that that will say in the further tutorials in the last video we have talked about how to create a spring application and which you can inject an object from outside and this for a dependency injection right so we have achieved that with the help of application context interface and we have to mention a spring tour XML file in which you have to define all the bins you require you have to mention are being ID and you have to mention a byte nothing for further further tutorials will you just have to update this XML why we are doing this is because in this video we'll talk about different type of configuration see when you talk about spring application and when you talk about application context so this is responsible this object is responsible to give you those beans but the problem is you have to configure it somewhere right so so we want vehicle so we have to we have to configure somewhere that whenever I asked for a vehicle I have to provide a object of bike now this step of configuration is possible in two ways in fact in spring we have three ways the first way of configuration is using XML so this is what this is how we do XML based configuration the second way of doing this is using allocation based configuration again in this video we'll talk about annotation and third ways we can use Java configuration now we talked about Java configuration we have it's a very new type of configuration for spring initially it was XML then in the some versions we have introduced annotation and in the latest versions we have talked about we talked we talked about we have Java configuration so in this video we'll see how to do annotation based configuration and to use annotation based quantification we have to introduce some lines here so we have to introduce this to this three lines so this one and there's two lines again you can get this from Google so just go to Google and search for how to do a nutrition quantification XML on Google so you will get this this line there now or you can just copy you can just write this file now what we'll do is we're trying to configure this with the help of annotation so some changes here first I will not say I want a vehicle I will say I want a car okay simple I want a car now the next thing is why I have to configure it here I will just come in this part okay let's see what happens if I come in so if I run this it says no such beam definition exception okay so no one be named car okay so it's not able to find a beam what we can do is we can specify yourself you can specify here itself in this car itself we can say at component now we can say this card is a component so whenever you want to achieve an equation which complication just go to this card class and say add component now to use add company where to say control space it will give ya so it's a stereo type annotation and it is add component now whenever you use annotation based configuration we don't have to mention that inside our XML file simple we can simply say the component so this component is same like writing this line XML but hold on in XML we mentioned the vehicle name right so we have to mention ID which is vehicle we are not mentioning anything here so what will be the default name for this car and here's the default name for this car will be will be car so that name will be non qualified and D capitalized which simply means we don't have to use a package name we can directly use a class name because in general the class name for this is comm dot Naveen dot the squad car so we have to remove all those packages we just have to take a car so you can see we have we're getting a citation here so we have to just have to say car but it should be d capitalized so we don't have to use the first C as capital we have to make it small so the default name for this bean is this car CA r and now if we run this and boom we are again getting an error it's is no bin named God it's because when you try to run this application every time it will go to this file and it says ok we are not getting any pen definitions here but you will say we havea right we in this car class we are defining component but the problem is you know that we have you have written component your Spring Framework doesn't know that you have written the component now to let your Spring Framework know that you are using the annotation based configuration we have to use a line here which says context is configured with annotation configuration and your ok not this one not this line sorry we have to use context components can and you have to mention the base package work you mentioned calm touch is it knowing no so calm dot loving dot that is co dot yeah we have to just mention the package name and now let's run this so if you now film this you're getting children a simple now what if I write bike and run and of course for by calculating the error it's because in the bike class we have not mentioned at component so you have to mention that component here simple and now if we run this it says bara simple so this is how we have to we have to write an addition based conjugation so the further tutorials will be working on both so we'll be saying something with XML based configuration then we'll see annotation based configuration but for the advanced tutorials we talk about lis about annotation based configuration because that is what highly used so in the last video we have talked about this file so we have got Java and we have cut class we have a pin which we will have a main function then we have bike and then we have a vehicle interface this is our configuration file and this is my poem to XML which is for mavin now what we'll do is just to go beyond the example just go ahead of this let's create a new file and then we'll name this class as tyo and this style what will be having is we have so let's say we have private string and we'll name this variable as brand ok so let's say if we talk about tie also time and we have different brands or maybe m RFC 8 or all different of this stone maybe so we have lots of companies who make tiles so for this brand we require get out and set o so just take this getter and setter here and we say ok now if we got get a set of for this brand now when this let me print not here maybe okay so let's let's print our data and so it's so if I try to print the object of Thai I want to print this data so I will just use a two string method just to print the data of the tayo and I will use this which will print the brand name now I want to create the object of the taya in this class ok so let me just comment this vehicle for time in let me just use these comments let me get out it off tire now how do you get object of tiles that we have to say it tire they have to say T equal to new tire right but again whenever you use a new keyword it adds some dependencies so what will do is will remove this dependency and we can simply say I need our tire object so I will say context dot o ignore the arrow okay so context dot get B and then here will mention I want a tire but hold out we are not we have not mentioned this tire in our XML files so if I go to XML file you can see we don't have anything called as tire so either we can use eigen we can define this tire using allocation based conjugation as we have done in the last video all we can do with the help of XML based configuration so just for the example for this type of example for the example what I have to explain I will use XML for tire so to use XML so we have define a pain tag in this ID fifth dimension we are working with tire and then we have to say class equal to and then it is calm torch knowing that the disco dot tire and again I know I should not use a package name with capital letters but that's okay for the example okay so now I got an object here and yeah got it won this so let's sprint let's print T here and now if I print T so if I done this you can see output is tire and branch is equal to null oh why not it's because in this die of they are creating a variable called as brand in case of car in case of bike we don't have any variables but if you talk if you talk about tire we have or shrink or as brand then we have one more dependency here so brand becomes our dependency that string variable becomes a dependency for your tire class now how to add that dependent or taught to solve the dependencies so we have to so for this class which is tire this brand here is a property right so spring allows you to set a property so we have here we have a property named as brand and then we can specify our value so we'll say the value is M R F so you belong it's a matter of time and now if it on this here we go we are getting our brand as a model as simple as that so we can simply specify they brand the name or the property inside a bean tag this is how we do it in XML format simple so let's say in future if I have changed from Amara to let's say see it so let's say if I you see it here and now I find out this application so if I run this it will be brand see it simple so that's how you add a property tag inside inside your being so in the last video we have seen we have go to this class which is app and the entire and we are trying to create the instance of tire here so for that what we are doing is we are saying coyote equal to then in using typecasting so we have to use context dot get bean we have to mention tire so if you mentioned this line here you will get the instance of tire from we are getting the instance so this this fine is helping you for the instance and then we have used a property tag to assign the value for the tire so if you can see in this tire we have a variable for this brand and then I am assigned the value brand using this property tag now whenever you use this type of properties so basically you're using a method which is set up also this one so we are using this method which is set okay so whenever you use a property tag inside your bean you are actually using a setter here but it's not compulsory that we can only assign the value using setup we can also we can assign a value using constructor so whenever you use Seto it is for the setter injection whenever you use constructor it will be called as constructor injection now in order to use constructor injection the first thing we need is we need a constructor here so to assign a constructor will use will say so okay give me a constructor with fields yes and then with brand so I got a constructor here and then when once you've got the constructor we cannot use property here so we'll come in this part okay now once you got the comment let's define a constructor so how to write a constructor so just say controls base you will get constructor Arg as the suggestions use constructor Arg and then you can mention our value so in this value will specify let's again MRF okay and then this MRF will go to this ty of parameter which is brown and it will assign the value here simple right and let's run this so now if I run this so you can see it is ground MRF simple so that's how you can use a constructor injection so let's continue from where we left in the last video so we have created this glass tire in which we have we are using a tile constructor for construction constructor injection what we'll do is we'll remove this constructor injection and we'll die we'll go back to the property in fact we can skip this property part also we just we don't want to assign any value we're just going for the object of tire let's run this just to verify the we are getting the output so we got an error says constructor not found okay so once we are making some changes so we don't want constructor okay so now it's printing browned as null okay when you get browned as knowledge because I'm printing this part so I will just find ty okay that's it I want to print the brand name it's just tire so now if I run I'm getting a tire that's it now what we'll do is every car needs a tire right so what we'll do is here let's create a object of tire now to create or difference of tire so we'll say excuse me so it is private we'll say tayo tayo and for this reference we require a gator and setter so we'll say right like shows and with my Gator Seto so it's here so let's select a tire and click on okay so you caught a tire Gator and set up now once it got the Gator and Seto Oh so let's verify so for this tire I have a component so so basically we are using annotation quantification here but for tire we are still going forward what you say we have xml-based configuration so will it work let's see the thing is when you whenever you mix a annotation based configuration and XML mission configuration we can do that is called as mixed con figuration so we can use both at the same time okay so in this example we are using both so let's try to run this so we are using tayo okay let's let's print so in this dryer if I sprint drive so let's not print car let's say it's car plus and let's also print the tile okay let's print let's print tayo so whenever I try to print tire it will call the to string method of this and we sprint it's walking okay and let's run this now so if I run this it says it's walking because we are we are superior to change this so in app let's come back to let's create object of car again so let's not make it vehicle let's make it car this is what we have done in the first video if you remember let's make it car and we asking for a car let's not use tire okay just say obj dot drive simple knife Iran this oh it says God and it prints null so somewhere we are not getting this object we are not getting this tire so it's because whenever you want to use this tire here so this fourth for this class car the tire here is a property right so we have to go here in XML file and then we have to define this eigen value define this car here and then we have to assign the property so will not do all those things will try to use annotations here so for this we have to use an annotation which is called as Auto biotin so when you use a wire cutter wire annotation and if you run this so you can see it's a scar it's working so what this auto by the hydration will do is it will check okay we need a car so if we need to tire so it will xml file and we'll say okay so if you need a tire you will get instance of this tire simple so that's how annotation annotation work but can I can I remove this I don't want to use XML based complication now so will it work of course not because God is the component so I'm not using XML based configuration so that let's come in this bar just to show you so I'm not using XML based quantification I am using annotation based configuration and this tire is not of component so if you have to mention component here also so we have to use add component and now if I done this you're getting the same output which is car it's working so what other changes we have made so we have we have a class car in which I am using auto while annotation and then we have our tire pin on which I am using add component annotation so you can see if we are not using any XML configuration everything is annotation based configuration so this is auto wire annotation I'm also using component and then this is component annotation in this video we'll talk about Spring Framework will also use mavin in this and will try to configure a spring application with the help of annotations so after after watching this video you will understand what is Spring Framework will understand how to use mavin to create a spring application and you can configure a spring application with the help of annotations now in fact I have already created some videos for Spring Framework using XML configuration so in this video we'll talk about annotations move more focused on annotations okay so we normally achieve dependency which is spring the dependency injection with the help of Spring Framework right so what are the suggestions if you want to know about the basic concept of spring you can you can go to the playlist of Spring Framework just there are some three to four videos you can understand what is Spring Framework how to implement Spring Framework this video is specifically for annotations okay so you will find the link in the description area of the Spring Framework okay so let me create a new project we'll be creating a mammoth project because we work we don't want to download all the device required libraries right we can ask mavin to give you that for you so we'll say mavin project now since we are going for a simple spring application we'll go for a QuickStart which is a mapping app type you can go for spring web for their application you can go for a quick start for Kota application I will let me convert in his code and the artifact I will give as spring annotation so we'll say spring an oh okay that's the project name so you can see record our project where it is it is here and if I expand this we have okay so we have this P or M file now since we want to work with Spring Framework we need to add those spring dependencies here right so what we'll do is we'll for spring dependencies just have to go to Google and search for mavin repository because you will get all your la base from here okay and here you can search for spring Corps that's what we search for spring context so we need to get this spring context here we can just take the latest version which is for point or will one point four point one point ninety it's always better to have a one lower version because it will be stable for sure let me copy this if I go back to the MAV and paste it here you can see it is downloading the Jarl files if I go to mavin they got all the required Java files so it will download everything from the internet if you have already done this earlier so it will be having a local repository which is dot m2 folder in your documents so you can just go to your home path search for dot m2 folder you'll be having all these jar files there okay that's the advantage of using mavin here okay so once we got this let's start with the actual work so what we need here is we have a class and well I will name this class as samsung s7 so I want or white Y dimension s7 will just simply says Sampson so we have a phone which is Samsung here and in this Samsung class we have a method will name that method as public void convict so that's the method name which is configure and in this config I will simply print I will print oh this is a clip so we have to say s out and in this will print the configuration of this phone we can say this is octa-core comma this is 4 GB RAM so I'm talking about Samsung s7 to be specific we have 12 megapixel camera okay so that's camera right so we have this Samsung glassier and what I want to do now is I want to create this I want to create this I want to call this config method so in order to call this config method is for that we require a main function right so we'll go for a main function here ok so I have my main function inside this app so app is a class inside this I have to call that Samsung right so in order to call Samsung we can simply say as Samsung we can say this is s7 equal to new Samsung s7 so sensing and at the end we can say s7 dot config right and if you this application will be getting the output as the quantification right but the problem is we don't want to go for this because this is not dependency injection right what we want to achieve so using spring you should be able to inject this object so in order to inject this object we can ask our factory which is application context should give you the object of Samsung for that way to create object of application context we can say this is Factory equal to so in order to create object of application context we have to create we have to use a class which is annotation conflict in fact if you remember in XML we use glass but XML and this we have to use annotation config application context in which you have to pass okay first we need the object of factory and then here we can specify factory dot get been you need to specify two things the first thing the inter specify the class name of which you want the object we can say I want the object of samsung dart class okay and we it also yeah does done so we to specify that we want the object of Samsung class right and if you want this application now so what we are doing we are asking factory to give you the object and if I done this code okay it's something is happening regard oh we got an error here it says illegal State exception is because okay we have not mentioned the configuration file here so when you go for an XML you mention the XML name right which is spring dot XML in which you have to specify something like this you have to specify that or not this one you have to specify you should have not regular to specify Sampson and instead of CPU we have to say we want a phone so when you say we want the phone you will get a Samsung right so this is what we do in when you work with XML type of configuration now we are not going for an XML type of quantification we are going for annotation which qualification so in order to use annotation based configuration what we need is we have to create a class who will responsible for this so I will create a class who will provide me the configuration since we are walking with annotation so we could a class animal in this class as appconfig we can give it any name doesn't matter and since this class is a configuration class or this class is responsible for the configuration we have to use an orientation which is at configuration so as soon as to specify at configuration now this file this class is responsible to create to give you those objects so in XML what we do we specify this stuff right so in inside your XML or inside your annotation what we can do is we can create a method and we'll this method will return you the object of Samsung which is Samsung and we'll name this as gate 4 so method name is gate phone okay and we can simply say return new Samsung sounds good right so now as soon as you run this code now it will try to fetch the object from here let's try let's see what's happening oh we need to specify this stuff here also right we have to specify this is app config dot class so we to specify from which con which configuration class you are working with so this factory need to know about the class you're working with okay let's go back to the app config and everything seems good and if I run this code again if I go here record another error now which is no such bin definition found so we got the class so if there's no I don't know of class but it is not able to find the bin type of Samsung the problem is inside your methods you have to specify that this method is a bin retooled it will return you our bin so that's the annotation we have to use in order to create or that dependency thing work and if run this code now can you see that we got the output so you can see we are not using any XML file here everything is annotation based awesome right so this app config needs the object of or within this app config you have to specify at configuration we should specify that this is a configuration file and for every object so let's say in XML we need one more so let's say I want an object of mobile not a mobile so every every phone is depend upon the CPU right so let's say I have a bin here ID will say this is CPU and we have a class who creates this CPU let's say I'm talking about Snapdragon right so we can say this is Snapdragon so if we have a CPU of model Snapdragon so now if I if I want the same thing if you want to achieve the same thing here we have to create another method we will say get CPU or get Snapdragon or anything it will written you have the object of Snapdragon I think you can go on so let's try to implement that let's see how to implement that stuff here so what will what we we need here is so you've got the idea about the concept of dependency injection with the help of annotation right so what we'll do next is we'll try to create another class or not the class but we will we want an interface here so what I will do I will go to interface will say this is interface and this is mobile processor okay because every MOBA every phone needs a processor right we click on finish so what this phone processor or this mobile processor will have is it will have a method with name will say this is method name is void process that does the stuff it will do so we have a void process method and to implement this void to implement this mobile processor we have one more class and we'll name that class as what we'll name this class as we have a class which is so the first class is Snapdragon okay and something more so this Snapdragon will implement our interface which is with the name of mobile processor right so this is the interface and when you when you click on finish you can see we got a method which is process but by default is empty right so what I will do I will say this out I would say world burst CPU right so we have a mobile processor which is Snapdragon and inside your Samsung class so every phone needs or processor right so in this advocate the object of mobile processor is a mobile this is so and okay mobile first I will say this is CPU right and for this we require get in center so I will just right click here I would say so get a set up because that's a variable right so we quickly get a circle for this we click on OK and let me remove this all extra tags which we don't required here ok removed okay so we got get CPU SEC CPU and when I print the configuration I also want to print the person so I will say CPU dart process sounds good absolutely let me repeat what we are doing here when I done this application now it will call the config method of Samson and this Samsung method of this the config method will call the process method which is a part of mobile processor now the question arise if I don't it will it work and the answer is no of course right because we have not created the object object for CPU it is just declaration right and we're trying to type the coin trying to access the object of course it will give you an error so if I go to this app and if fernanda's so we were expecting the outright with a nullpointerexception then how to provide that object how to provide this object for mobile CPU again I will not use new object new keyword there so what I will do is I will create the bean inside qualification for every object need to create a bean annotation that's compulsory and we can specify a method name here we can say this is public it will return the object of mobile processor because that's what we want and we'll name this we can name it anything we can say this is get again so this is get versa so anyway that name doesn't matter and this will return now we need to provide the concrete implementation so we can say this is nap dragon so specifically we are saying it should return the object also not dragon ok so now we have created that mobile person object also right but inside this Samsung how it will connect will it connect directly this driver on this core we are still getting the error it's because we are not able to connect it so in order to connect these two things in your Samsung class we need to say this is at O at Auto wire so what it will show it with such I need the object of CPU I will check in the app configuration we already have a method which returns mobile processor so it will take the type of the return type it will check the return type so this auto wired inside the annotation part comes as by default is by type ok it will not check the name it will check the type and if I don this code or not this one if I run this app boom can you see that we got the output as world best CPU it's because just you can see in Samsung we have still not created the object it is it is done automatically and that's the power of this override annotation quite simple right so let me just repeat all the stuff here which we have done so we have created a class with yes we have cater that we have created this app class in which you have a method which is main in which you have application context object which is factory and using factory we are getting the object of Samsung which is get being in package you can specify Samsung dot class and then we are saying as seven dot config write quite simple but the problem is when you say get B and you have to provide those being inside your app config so you have to specify this class seal so this is your confirmation class we can have another country confirmation class also let's say you have one more conflation class as my app config so you can have two three four you can have multiple conviction files but when you whenever you are working with one conformation file you have to mention that file here inside your app configuration you are specifying two beans one is the gate phone and the second one is cat processor and then we have Samsung class via mobile person then we have Snapdragon right so it's that simple but what if I say you don't have to write these two things also that means if I did it this way let me come in this part while you did it so if I come in this part it should it should still work and if I run this code it's not working again see we got the others then question Allah is how to achieve that is it possible to commend those part or not even writing those parts rate should work mmm we say that so what we'll do is we'll see that stuff in the next video how to do that although stuff so now in this video we will see how to create bins with without using this bean tag so this bean tag here is a replacement for this beans tag inside XML right but I don't want to do this thing also it so it literally I move this stuff and still it should work and if you run this without those stuff we are getting the error right so it's saying no qualifying bean type so how to achieve that so to make this as a bean by default you just have to write a annotation coruscant component so every class of which you need an object example for Samsung we want your lit of Samsung's I just make it component in fact we require object of Snapdragon just write add component so the advantage of adding add component is by default will be getting the object of Snapdragon and Samsung okay you don't have to get any any beans for that but since we are saying that we want to go for the automatic configuration which means we don't have to specify anything for that we need to use an extra annotation here with configuration and we have to say all the components are predefined so just type component scan it will scan all the components for you and in this you have to mention the base package in which package you have all these things so we have in package we just calm dot telesco telesco dot spring demos or spring I know so that's the package in which you have all the required classes right so you can see we have all the classes we have Samsung we have app config inside or we have something we have Snapdragon inside only one package so if you have multiple package you can't specify my TV package using comma okay sounds good I think it should work now if I run this code everything sounds everything looks good if I don't this code boom can you see that we got the output so we don't have to specify any bean tag I just have to say add component scan it will scan all the components in your project on this specific package okay so is it's that simple now what it is doing is it is going for by type okay by default every example see in this if you go for example type every class will have a name light so that's an ID what about this thing since we are writing component what it whatever bits name so by default the name will be so you have to give the body for the name will be Samsung okay so it was remove it will make this small as it will cap it it will make that capitalized and small s so this is default name for that so even if you don't mention the name it will be Samsung if you wanna change it you can change it you can say this is let's say my samsung okay you can do that also but by default if you don't mention it will be Samsung so if you write this component annotation the default ID will be given as the name which is non qualified just non qualified and what non qualified and D capitalized so just just just ignore the spelling there so it is non qualified and D capitalized okay which simply means you don't have to mention the package name so your your name will not be have a package name and it will be with it was charged with a small character okay so which is going for byte type right so when you specify component scan it which is searching by type now let's say so we see in this Samsung we want object or cobalt alright so we are getting object of snapdragon what F if I create a new class and we'll name this class as mediatek okay that's the model name or that's the company name and this mediatek also implements mobile processor and this i will print second best this is not the second best CPU but still let's ride it second best now the problem is we need to mention this is also component right we have to specify this even this is component so here just go okay what's that now so this art component yeah so now can you see we have two classes not dragon and mediatek both implements mobile also and Samsung needs mobile bills so if you have not mentioned we have we want no one where I mentioned we wants not drag Android now this time how to specify that we want snapdragon v1 media tag so if I run this code now there will be an error because of the confusion because the confusion is so you can see there is a error which is no unique bin definition exception which means for the same interface we have two classes which is Media Tech and snapdragon can you see the names here small m and small s because of the names there so how to make sure that we want let's say if there is a confusion I want mediatek only I don't want I don't want what I don't want Snapdragon so we can specify something like this primary so if you specify primary ok so it will if there's a confusion it will take this one into consideration the media tag and if I'm this so since we don't have any confusion we got the output which is second best and second message may detect right and if I copy this if I cut this primary and if I paste this into Snapdragon now and if I run this code we should be getting world's best CPU we are getting that oh they're getting exception the way I have pasted it oh it's not not paste it okay let me run this oh can see that we got one best CPU so that's how we use a primary annotation okay we have one more thing but let's say let's say I don't want to mention prime annotation here okay and in and this Samsung itself violating auto why'd I want to mention the name I want Snapdragon all I want me attack so you can do that with the help of qualifier so if you don't if you're not going for primary which means you want to specify which you want so you can in qualify you can mention I want media like I don't want Snapdragon I want media tag so it went that will do and if I run this code we got the output we go second best why second is because we are measuring qualifiers Mirotic we can also specify it as nad Dragon Knight will fetch Snapdragon right so you can see how many annotations we are using here so this is spring so this is this topic is called as spring code annotations okay so if I go to any any any of this annotations here if I click on component so I can say it was introduced into 0.5 so if you have if you have worked on spring which is before 2.5 we have to use all we have to use all this stuff which is XML based quantification now since we are using a spring which is we are which is I guess for so it will this annotation works then okay so we have so just remember how many annotations we are working with we are working with add component which is for the object or we can specify the class object we can write Auto wire so that it will search for the object itself we can specify the qualifier to match the name we can specify what we can specify at configuration which means it will it is a configuration file for you add component scan which means it will scan all the components for you then we have that's it these are the configuration these are the annotations we have worked on this in this project so that's your spring annotation if you have any questions any doubts they can just post post it come in section in fact you can give me also some feedback your if you liked this video or something like that now that's it from this video do like the video and do subscribe for further videos thank you so much for watching
Info
Channel: Telusko
Views: 1,003,708
Rating: 4.8954811 out of 5
Keywords: telusko, navin, reddy, tutorial, java, python
Id: If1Lw4pLLEo
Channel Id: undefined
Length: 89min 59sec (5399 seconds)
Published: Thu Jun 13 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.