This is true because the default scope of a bean in Spring is singleton, which means that only one instance of the bean will be created and shared by the entire application context. The @Bean annotation on the accountRepository() method indicates that this method will return a bean that will be managed by Spring. However, this method will not be called every time the bean is needed, but only once when the bean is first created. Therefore, only one AccountRepository bean will be instantiated and injected into the TransferService and AccountService beans.
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit