How do I force a spring container not to return a singleton instance of a bean?

后端 未结 2 1964
刺人心
刺人心 2021-01-01 15:59

When I call getBean(name) on a BeanFactory, I get back an instance of the bean defined in the application context. However, when I call getB

相关标签:
2条回答
  • 2021-01-01 16:36

    The default scope is singleton, but you can set it to prototype, request, session, or global session.

    0 讨论(0)
  • 2021-01-01 16:50

    You need to tell spring that you want a prototype bean rather than a singleton bean

    <bean id="beanA" class="misc.BeanClass" scope="prototype"/>
    

    This will get you a new instance with each request.

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