I am learning Spring and the term "Spring Container" frequently shows up in the text. However, I know "container" is not used only in Spring (EJB container etc) so what does it mean when used in the context of programming?
-
What do you mean by `I know "container" is not used only in Spring`? They wouldn't be using the term `container` if ti wasn't the case. – Buhake Sindi Mar 16 '12 at 08:53
-
You should ask in the programming section – Michael Laffargue Mar 16 '12 at 08:53
-
After receiving 8 upvotes I found a duplicate: [Definition of a Java Container](http://stackoverflow.com/questions/7151206/definition-of-a-java-container), sorry, not intended. – Tomasz Nurkiewicz Mar 16 '12 at 09:09
-
1I tried searching but did not see that sorry. – LuckyLuke Mar 16 '12 at 09:16
-
@Viper: please use *@* symbol to mention who you are responding to (like I just did), otherwise other people won't get the notifications about your comments concerning them. – Tomasz Nurkiewicz Mar 16 '12 at 09:28
2 Answers
The container is something that contains something else.
In spring: Spring container contains beans (Java objects that are subject to dependency-injection)
Servlet containers contain servlets, filters, listeners, etc. and manages their state and lifecycle. There are also similar portlet containers
EJB containers contain EJBs (stateless, stateful, message-driven) and, as above, manage their pooling and lifecycle
java.awt.Container
"is a component that can contain other AWT components"
As you can see the role of the container is to own and manage a set of objects so you don't have to instantiate them directly.

- 334,321
- 69
- 703
- 674
-
3I think that your answer would be acceptable if you left only the 1st sentence. ;) – aviad Mar 16 '12 at 09:05
-
1No it wouldn't. I'm with the OP, the term container is such a loaded term in software and if it's so generic it shouldn't be used. Atoms are containers according to the first sentence. They contain protons and electrons but who cares? And who cares that a 2D box in a diagram contains empty space? There must be more to it. What do we do with the contents? Why do we want to put them inside a container? e.g. "contain something that you might need global access to in your code base to invoke dependent logic"? – Sridhar Sarnobat Nov 18 '15 at 00:35
-
1This is key: "to own and manage a set of objects so you don't have to instantiate them directly." – Sridhar Sarnobat Nov 18 '15 at 00:41
What you're asking is a bit obscure to me. I guess you are asking what "containers" do in general.
My comprehension is that container is a pool managing a series of objects/beans. For example there is the web container TOMCAT, the general IoC container in Spring, or even the thread-pool has also similarities. Container deals with mostly all the business of what it contains, like the life-cycle, the dependency between each object. And what we need to do is just to generate an object and put it to container, and get it when in need.
Wish that will help.

- 587
- 2
- 5
- 11