Refer to the exhibit.
Based on the default Spring behavior, choose the correct answer. (Choose the best answer.)
Refer to the exhibit.
Based on the default Spring behavior, choose the correct answer. (Choose the best answer.)
In Spring, by default, all beans are singleton scoped, which means that the Spring container will create and manage a single instance of the bean within the application context. When the accountRepository() method is annotated with @Bean, Spring will ensure that there is only one instance of AccountRepository in the application context, regardless of how many times it is requested by other beans like transferService() or accountService(). Therefore, only one AccountRepository bean will be instantiated.
A is the best answer
Default scope is singleton, doesn't matter how many times you request the bean.
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.