How does Spring @Configuration cache references to beans

前端 未结 2 1061
北荒
北荒 2021-01-19 03:58

How does Spring prevent a second call to bar() when using Java based configurations?

I\'m wondering compile time annotation processing or by proxying the method?

2条回答
  •  余生分开走
    2021-01-19 04:41

    Spring does not "prevent" a call to bar(). Instead, at startup, spring generates a list of @Bean marked methods then calls each method one time. If you want, you can call bar() a hundred times. Spring, however; will only call it one time.

提交回复
热议问题