SpringContainer
SpringContainer
SPRING CONTAINER
• Spring Container is a program in Spring Framework that
manages the objects.
• The container gets its instructions by reading configuration
metadata to instantiate, configure, and assemble the objects.
• We can represent configuration metadata in different forms,
• XML, Java annotations, Java code
SPRING CONTAINER
• Spring Container has the following responsibilities:
• 3) Link/Inject objects
• @Configuration
• public class EmployeeConfig{
• @Bean
• public EmployeeBean permanentEmployee(){
• return new EmployeeBean();
• }
SPRING CONTAINER
• @Bean(name="contractEmployee")
• public EmployeeBean otherEmployee(){
• return new EmployeeBean();
• }
•}
• Method name becomes the bean id by default. we can provide
the name of bean as per our choice by specifying ‘name’
attribute of @Bean annotation .
SPRING CONTAINER
• When to use BeanFactory container vs.
ApplicationContextContainer?
• If you are using small scale, light weight spring based
application, prefer using BeanFactory container as it takes less
memory to work.
• If there is a memory limitation in place, prefer using
BeanFactory container. For example, mobile apps, embedded
system apps, IOT apps etc.
• In all other heavy weight apps where memory limitation is not in
place, such as web apps, enterprise apps, distributed apps,
desktop apps etc., prefer using ApplicationContext container.
• We should prefer using ApplicationContext container wherever it
is possible to use.
THANK YOU