Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is container in spring framework?

  1. 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?

  2. Can Spring IOC be used in Spring MVC?

like image 801
theJava Avatar asked Jan 03 '12 06:01

theJava


People also ask

How many containers are there in Spring?

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.

What is Spring container and beans?

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.

What is Spring container and IoC?

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.

Which container is used in Spring boot?

The Spring Boot starters ( spring-boot-starter-web in particular) use Tomcat as an embedded container by default.


3 Answers

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:

  • Like the JVM is a container to run Java Programs,
  • A servlet container (i.e. Tomcat) is the thing that runs servlets
  • An EJB-Container is the environmet where EJB live (see this wikipedia article (in german, but you can use your browser translator))

The same way Spring is the container where Spring Beans live.

like image 89
Ralph Avatar answered Sep 20 '22 04:09

Ralph


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.

like image 31
Aravind A Avatar answered Sep 19 '22 04:09

Aravind A


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

like image 38
kosa Avatar answered Sep 19 '22 04:09

kosa