Spring:有还是一个容器?
它如何正确:
“Spring 一般来说是一个容器,它管理对象......”
或
“Spring 使用/包含一个容器,它管理对象......”
我的意思是,IoC 容器是 Spring 框架的一部分,正确的?或者你可以说,Spring 是一个容器吗?
谢谢:-)
[Spring框架3.0.5]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Spring 是一个遵循控制反转范式的框架。控制反转是一个原则(实现细节并不重要)——“反转”是指您在代码之外的配置中连接 Bean。有很多方法可以做到这一点。一个类比是面向对象编程。面向对象是一种范式,就像 IoC 一样,有很多方法可以实现。就像面向对象一样,有些细节你应该知道,但范式存在于更高的层次。
Spring 是一个框架,因为它包含许多库来让您的生活更轻松。这里细节很重要;您需要知道 JmsTemplate 或 TransactionTemplate 如何工作才能使用它们。
您的问题主要是关于描述 Spring 时使用的最佳词语,这是一个很有价值的问题。现在看这张图片,取自 此处。
首先,高级词语包括FRAMEWORK。应用程序还有一个称为容器的逻辑部分,它被进一步划分为多个组件。容器的文档是 此处。当人们谈论 Spring 时,他们主要会说它是一个框架和一个 IoC 容器,具体取决于他们如何使用它。也许准确地说 Spring 是一个包含 IoC 容器的框架。
重要的是,您可以使用 Spring 框架中与 IoC 无关的部分、仅与 IoC 部分相关的部分,或者两者兼而有之。
Spring is a Framework that follows the Inversion of Control paradigm. Inversion of Control is a principle (the implementation details do not matter) -- the "inversion" is when you wire up your beans outside of the code, in the configuration. There are many ways to do that. An analogy would be Object Oriented programming. Object Oriented is a paradigm, just like IoC, with many ways to do it. Just like with OO, there are details that you should know, but the paradigm exists at a higher level.
Spring is a Framework because it includes a lot of libraries to make your life easier. Here the details matter; you need to know how JmsTemplate or the TransactionTemplate work to use them.
Your question is primarily about the best words to use when describing Spring, which is a valuable question. Now look at this picture, taken from here.
First, the high level words include FRAMEWORK. There is also a logical part of the application called the container, that is further divided into its components. The documentation for the container is here. When people talk about Spring, they primarily say its a framework and an IoC container, depending on how they use it. Perhaps it is accurate to say Spring is a Framework that includes an IoC container.
The important thing is you can use parts of the Spring Framework that have nothing to do with IoC , just the IoC part, or both.