Professional Documents
Culture Documents
Autowirnig Annotation Stereotype Based Lyst8375
Autowirnig Annotation Stereotype Based Lyst8375
-> It will inject one bean object into another bean object automatically
using annotations
-> Annotations used in this case are :-
1. @Required
2. @Autowired
3. @Qualifier
------------------------------------
=> @Required :-
-> It is used to force the Spring Container (IoC Container) for Dependency
Injection
-> If we use @Required annotation then DI is necessary/compulsory
=> @Autowired :-
-> It is used to provide DI without using <property> tag or any other
attribute in XML Configuration file
-> @Autowired can be used with setter methods or properties/variables or
constructor
-> If we dont want to use @Required annotation then we can use "required"
member i.e. @Autowired(required = true)
-> It uses by default "byType" mechanism
=> @Qualifier :-
-> When we have multiple bean definations for single bean class in spring
configuration file, then confusion may occur that which bean it has to inject. So
to remove this confusion @Qualifier is used i.e. @Qualifier("bean-id")
-> @Qualifier is used with @Autowired annotation
===================================================================================
========
----------------------------------------------
=> @Component :-
-> It is class level annotation. It is used to denote class as a component
-> Its functionality is :-
= It will scan our application for classes with @Component annotation
in provided package
= Then it will instantiate all those classes
= Then it will inject specified dependencies into them
@Component
class EmpModule -------------> EmpModule empModule =
new EmpModule();
{
---------------------------------------
1. @Controller
-> It is used with the classes that acts as controller
-> It is mainly used in combination with annotation handler methods i.e.
@RequestMapping or @GetMapping or @Post or @Get etc
2. @Service
-> It is used with the classes that provides some business logics
3. @Repositories
-> It is used with the classes that are responsible for providing CRUD
operations on database
===================================================================================
=========