spring中的bean

83 阅读1分钟

1、spring中的bean不是线程安全的,需要怎么处理
2、spring中bean生命周期,和容器生命周期的关系

spring bean

什么是spring bean?官方文档中写到:

A Spring IoC container manages one or more beans. These beans are created with the configuration metadata that you supply to the container (for example, in the form of XML '<bean/>' definitions).
Within the container itself, these bean definitions are represented as 'BeanDefinition' objects, which contain (among other information) the following metadata:
*   A package-qualified class name: typically, the actual implementation class of the bean being defined.
*   Bean behavioral configuration elements, which state how the bean should behave in the container (scope, lifecycle callbacks, and so forth).
*   References to other beans that are needed for the bean to do its work. These references are also called collaborators or dependencies.
*   Other configuration settings to set in the newly created object — for example, the size limit of the pool or the number of connections to use in a bean that manages a connection pool.

bean definitions中的属性

1637464703(1).png 抛出了几个问题,1、什么是IoC容器?2、容器是怎么管理bean的?3、bean是怎么通过配置文件进行创建的?4、bean创建的方式有哪些?