Spring Prototype scoped bean in a singleton

后端 未结 5 1382
你的背包
你的背包 2020-11-29 23:50

I am trying to inject a prototype bean in a singleton bean such that every new call to a singleton bean method has a new instance of the prototype

5条回答
  •  春和景丽
    2020-11-30 00:37

    Since Spring 4.1 you can use annotation @Lookup

    @Lookup
        public PrototypeBean getPrototypeBean() {
            return null;
        }
    

    Every time you will call method getPrototypeBean() - you will receive new prototype bean instance. Don't worry about empty method realization: Spring will override it for you.

    Read more in official documentation.

提交回复
热议问题