Spring Annotation Based Configuration Class Notes
Spring Annotation Based Configuration Class Notes
Based Configuration
fi
e
We need to write a code to create objects Spring IoC container take care of crea ng
and inject the dependencies objects and injec ng the dependencies
ti
ti
d
fi
fi
ti
ti
ti
Spring Framework Annotations and Terminologies
Spring bean: In Spring, the objects that form the backbone of your applica on and that are managed by
the Spring IoC container are called beans.
A bean is an object that is created and managed by a Spring IoC container.
@Con gura on: Used to indicate that a con gura on class declares one or more @Bean methods.
These classes are processed by the Spring container to generate bean de ni ons and service requests
for those beans at run me.
@Bean: Indicates that a method produces a bean to be managed by the Spring container.
@Component: Indicates that an annotated class is a “spring bean”. Such classes are considered as
candidates for auto-detec on when using annota on-based con gura on and classpath scanning.
@ComponentScan: This annota on is used to specify the base packages to scan for spring beans/
components.
fi
ti
ti
fi
ti
ti
ti
fi
ti
ti
Spring Framework Annotations and Terminologies
@Quali er annota on is used in conjunc on with Autowired to avoid confusion when we have two or
more beans con gured for same type.
@Primary: We use @Primary annota on to give higher preference to a bean when there are mul ple
beans of the same type.
Dependency: An object usually requires objects of other classes to perform its opera ons. We call these
objects dependencies.
Spring IoC Container: Responsible for crea ng the objects (spring beans), injec ng one abject into
another object and managing the spring bean’s en re life-cycle
Dependency Injec on: Dependency Injec on is a design pa ern on which dependency of the object is
injected by the framework rather than created by Object itself.
Dependency Injec on iden es beans, their dependencies and wire/inject the depedency
ti
fi
fi
ti
ti
ti
ti
fi
ti
ti
ti
ti
ti
tt
ti
ti
ti