Spring autowire and prototype scope

前端 未结 3 644
醉酒成梦
醉酒成梦 2020-12-31 07:09

I have a class named Bar with the following annotation: @Configurable(autowire = Autowire.BY_TYPE)

On a private member I have the following annotation:

3条回答
  •  -上瘾入骨i
    2020-12-31 07:26

    The following links provide alternative solutions for such scenarios:

    1. http://whyjava.wordpress.com/2010/10/30/spring-scoped-proxy-beans-an-alternative-to-method-injection/
    2. http://benkiew.wordpress.com/2012/04/22/spring-2-5-x-create-prototype-instances-from-code/

    The first link talks about adding to Foo:

    @Component
    @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS, value = "prototype")
    class Foo
    

    Which will cause a new instance every call.

提交回复
热议问题