Home Subjects Java Programming Spring Framework Basics

Java Programming
Spring Framework Basics

Java OOP, collections, multithreading

12 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–12 of 12
Topics in Java Programming
What happens when a prototype-scoped bean has a dependency on a singleton-scoped bean in Spring?
A Compilation error occurs
B The singleton bean is correctly injected into each prototype instance
C The prototype bean becomes singleton
D A runtime exception is thrown
Correct Answer:  B. The singleton bean is correctly injected into each prototype instance
EXPLANATION

A prototype bean can depend on singleton beans without issues. Each prototype instance gets the same singleton instance injected. The reverse (singleton depending on prototype) is problematic.

Test
An enterprise application needs different bean implementations based on environment (dev/prod). Which approach is most suitable?
A @Bean with conditional logic inside @Configuration
B @Conditional annotation with custom conditions
C @Profile annotation to define environment-specific beans
D Manual bean creation in main() method
Correct Answer:  C. @Profile annotation to define environment-specific beans
EXPLANATION

@Profile allows defining beans for specific environments (dev, prod, test). Alternatively, @Conditional provides more granular control with custom conditions.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips