Java Programming — Spring Framework Basics
Java OOP, collections, multithreading
31 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 31 questions in Spring Framework Basics
What is the purpose of using @Bean method parameters in Spring @Configuration classes?
A To inject dependencies into the bean being created
B To pass configuration values from properties files
C To define bean relationships through method parameters
D Both A and C are correct
Correct Answer:  D. Both A and C are correct
EXPLANATION

Method parameters in @Bean methods allow Spring to inject dependent beans and establish bean relationships, enabling dependency injection at bean creation time.

Take Test
In Spring Framework 6.0, what is the role of the @EnableAutoConfiguration annotation in Spring Boot?
A It enables automatic bean registration based on classpath contents
B It disables all manual bean configuration
C It is replaced by @SpringBootApplication in modern versions
D Both A and C are correct
Correct Answer:  D. Both A and C are correct
EXPLANATION

@EnableAutoConfiguration (or @SpringBootApplication which includes it) auto-configures Spring beans based on jar dependencies on the classpath.

Take Test
What is the significance of the @Qualifier annotation when used alongside @Autowired in Spring?
A It improves performance of bean injection
B It specifies which bean to inject when multiple candidates exist
C It marks a bean as high quality
D It reduces memory consumption
Correct Answer:  B. It specifies which bean to inject when multiple candidates exist
EXPLANATION

@Qualifier resolves ambiguity in autowiring by specifying the exact bean name or custom qualifier to inject when multiple beans of the same type exist.

Take Test
Which annotation is used to provide external configuration properties to Spring beans in the 2024 Spring Boot version?
A @PropertySource
B @ConfigurationProperties
C @Value
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

@PropertySource loads properties from files, @ConfigurationProperties binds properties to bean properties, and @Value injects individual values. All are used for configuration.

Take Test
What happens when @Lazy annotation is applied to a singleton bean in Spring?
A The bean is created only when first accessed
B The bean is created at application startup
C The bean is never created
D The bean is created in a separate thread
Correct Answer:  A. The bean is created only when first accessed
EXPLANATION

@Lazy defers bean instantiation until it's first requested, overriding the default eager initialization behavior of singleton beans.

Take Test
Advertisement
In Spring Framework, which interface represents a factory pattern implementation for creating objects?
A ObjectFactory
B FactoryBean
C BeanFactory
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

BeanFactory is the basic container, ObjectFactory is for lazy bean retrieval, and FactoryBean allows custom bean creation logic. All represent factory patterns in Spring.

Take Test
What is the role of Spring's PropertyPlaceholderConfigurer in application configuration?
A It encrypts sensitive properties
B It replaces ${} placeholders with values from properties files
C It validates XML configuration files
D It manages database transactions
Correct Answer:  B. It replaces ${} placeholders with values from properties files
EXPLANATION

PropertyPlaceholderConfigurer (or @PropertySource in modern Spring) enables externalization of configuration by replacing ${property.name} placeholders with actual values from properties files.

Take Test
Consider a scenario where a Spring application needs to initialize a database connection pool at startup. Which method should be used?
A Use @PostConstruct annotation on a method
B Use InitializingBean interface
C Use initMethod parameter in @Bean
D All of the above are valid approaches
Correct Answer:  D. All of the above are valid approaches
EXPLANATION

Spring provides multiple mechanisms for initialization: @PostConstruct, InitializingBean interface, and initMethod in @Bean definition. All are equally valid.

Take Test
What is the difference between @Bean and @Component annotations in Spring?
A @Bean is class-level while @Component is method-level
B @Bean is method-level while @Component is class-level
C They are functionally identical with no difference
D @Bean cannot be used in @Configuration classes
Correct Answer:  B. @Bean is method-level while @Component is class-level
EXPLANATION

@Component is applied to classes making them beans automatically. @Bean is applied to methods in @Configuration classes, giving explicit control over bean creation.

Take Test
In Spring Framework, what does the @Autowired annotation do when autowiring candidates are ambiguous?
A It automatically selects the first bean found
B It throws NoUniqueBeanDefinitionException
C It uses the @Primary annotation to resolve conflicts
D Both B and C are correct
Correct Answer:  D. Both B and C are correct
EXPLANATION

When multiple beans match the injection point, Spring throws an exception unless @Primary is used to indicate the preferred bean or @Qualifier specifies which bean to inject.

Take Test
IGET
iget AI
Online · Ask anything about exams
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