I was going through this article
http://www.vaannila.com/spring/spring-ioc-1.html and here the term
container is used. The diagram below shows container. What is
container in this article? Is it a piece of code
or the bean
config
file?
Can Spring IOC be used in Spring MVC?
There are basically two types of IOC Containers in Spring: BeanFactory: BeanFactory is like a factory class that contains a collection of beans. It instantiates the bean whenever asked for by clients. ApplicationContext: The ApplicationContext interface is built on top of the BeanFactory interface.
In Spring, the objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. Otherwise, a bean is simply one of many objects in your application.
An IoC container is a common characteristic of frameworks that implement IoC. In the Spring framework, the interface ApplicationContext represents the IoC container. The Spring container is responsible for instantiating, configuring and assembling objects known as beans, as well as managing their life cycles.
The Spring Boot starters ( spring-boot-starter-web in particular) use Tomcat as an embedded container by default.
In this context, a container has the meaning of something that provides an infrastructrure needed by some components to live.
You can imagine it this way:
The same way Spring is the container where Spring Beans live.
Container is used to describe any component that can contain other components inside itself.
As per the Spring documentation here
The BeanFactory interface is the central IoC container interface in Spring. Its
responsibilities include instantiating or sourcing application objects, configuring such objects, and assembling the dependencies between these objects.
IOC is the core principle which Spring uses for Separation of concern concept . No matter what you use - Spring MVC, Security , Core , DAO integrations , you will be using the IOC principle.
Container is piece of code which reads bean config file and performs corresponding actions.
Yes IOC can be used with MVC. Here is an article about it. spring mvc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With