Spring bean 到底是什么? [英] What in the world are Spring beans?

查看:45
本文介绍了Spring bean 到底是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还没有找到我能理解的 Spring bean 的高级定义.我在 Grails 文档和书籍中经常看到它们被引用,但我认为理解它们是什么会很有帮助.那么什么是春豆呢?如何使用它们?它们与依赖注入有关系吗?

I am yet to find a high-level definition of Spring beans that I can understand. I see them referenced often in Grails documentation and books, but I think that understanding what they are would be beneficial. So what are Spring beans? How can they be used? Do they have something to do with Dependency Injection?

推荐答案

构成应用程序主干的对象由 Spring IoC* 容器管理的称为 bean.一个豆子是由一个对象实例化、组装和以其他方式管理的对象Spring IoC 容器.这些 bean 是使用配置创建的您提供给容器的元数据,例如,以XML 定义.

了解有关 bean 和作用域的更多信息SpringSource:

当您创建 bean 定义时,您实际创建的是一个创建由该 bean 定义的类的实际实例的方法定义.bean定义是一个配方的想法很重要,因为这意味着,就像一个类一样,你可能有从单个配方创建的许多对象实例.

When you create a bean definition what you are actually creating is a recipe for creating actual instances of the class defined by that bean definition. The idea that a bean definition is a recipe is important, because it means that, just like a class, you can potentially have many object instances created from a single recipe.

你不仅可以控制各种依赖和配置要插入到从一个对象创建的对象中的值特定的 bean 定义,以及创建的对象的范围来自特定的 bean 定义.这种方法非常强大使您可以灵活地选择对象的范围通过配置创建,而不必烘焙"范围Java 类级别的对象.Beans 可以定义为部署在多个范围之一中

You can control not only the various dependencies and configuration values that are to be plugged into an object that is created from a particular bean definition, but also the scope of the objects created from a particular bean definition. This approach is very powerful and gives you the flexibility to choose the scope of the objects you create through configuration instead of having to 'bake in' the scope of an object at the Java class level. Beans can be defined to be deployed in one of a number of scopes

*IoC:控制反转

这篇关于Spring bean 到底是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆