why not D ?
even if it is singleton because ther are no scope , the bean is still instantiated twice because it is called twice by two different @Bean methods (transferService() and accountService()).
A. One AccountRepository bean will be instantiated since the default scope is singleton.
In Spring, when a method annotated with @Bean is called multiple times within the same application context, the Spring container manages the bean instances based on the method's scope. By default, the scope of a @Bean method is singleton, which means Spring will create and manage a single instance of the bean within the application context. Regardless of how many times the method is called, only one instance of the bean will be created and managed by Spring.
Also, Spring intercepts the call to the bean factory method and first checks if the singleton is already created. So it makes no difference if accountRepository() is called or if a parameter of type AccountRepository is used in transferService()/accountService()
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Tolo01
11 months agorhuanca
1 year, 3 months agonesreenmhd123
8 months, 3 weeks agozakupower
1 year, 3 months agoquakquak3
6 months, 2 weeks ago