Skip to content
Sharp

Spring Core · interview question

Which of the following is a valid way to declare a Prototype scoped bean in a Spring configuration class?

Multiple choiceMediumchapter-9-curatedpremiumspring-corebean-scope
Choose one answer
Answer and explanation

Correct answer

D. @Bean @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) public MyBean myBean() { return new MyBean(); }

Why

To declare a Prototype scoped bean in a Spring configuration class, use the @Bean annotation with @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE). This ensures a new instance is created every time the bean is requested.

Test yourself on Spring Core

A free test with instant, explained results. No account needed.

Start free test
All Spring Core questions →