Spring wiring by type is slower by magnitude than wiring by name

后端 未结 2 1796
误落风尘
误落风尘 2021-02-02 10:34

In my project, I am trying to migrate all usages of

Foo foo = (Foo) beanFactory.getBean(\"name\");

into

Foo foo = beanFactory.         


        
相关标签:
2条回答
  • 2021-02-02 10:57

    Most Spring apps wire things together on startup, rather than grabbing beans from the context at runtime. Even still, unless you are changing your application context a lot during the regular running of your app, you should not ever fetch a bean more than once.

    Given that, if your users are complaining of slowness, it seems your real problem is too many bean lookups; your use of a slower means of doing so has just surfaced the real problem.

    I would try moving to Java Config (configure your dependencies in Java, supported in Spring 3.0 I believe) and configuring your app to wire all beans at startup. This also has the advantage that your app just won't start if dependencies can't be met.

    0 讨论(0)
  • 2021-02-02 11:04

    This problem is now solved in Spring with the resolution of SPR-6870. See the resolution comments there for details. The fix is available as of versions 3.2.0.RELEASE and 3.1.2.

    0 讨论(0)
提交回复
热议问题