0

Is a prototype bean created faster by the spring container than a singleton bean? How much if yes?

Maybe some background for the question. Assume that we have the context definition which contains a lot of bean definitions. And the application is a 'short running task' I wonder if I can speed up creation of the context by defining all beans as prototypes - because in this case it doesn't matter if they are singletons or not.

4

1 回答 1

1

这两种方法在创建的 bean 数量上完全不同。

  • 当 bean 有一个scope="prototype"this 意味着每次你请求一个对应的 bean 时都会创建一个id的 bean 实例。

  • 当 bean 没有scope设置属性时,这意味着在第一次加载上下文时将创建单个实例并将其共享。

我相信创建原型和单例 bean 所花费的时间(如果不相同)非常接近。

于 2013-10-23T14:09:36.773 回答