问题
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?
回答1:
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.
回答2:
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.
回答3:
A Web application runs within a Web container of a Web server.The Web container
provides the runtime environment through components that provide naming context
and life cycle management.
Ex. Container in case of java is the runtime environment and the implementation of API give by java .
Like
1. Servlet container is responsible for managing the lifecycle of servlets..
来源:https://stackoverflow.com/questions/9734242/what-does-container-mean-in-the-context-of-programming