0
0
Spring Bootframework~5 mins

@Configuration and @Bean in Spring Boot - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the @Configuration annotation do in Spring Boot?
It marks a class as a source of bean definitions. Spring reads this class to create and manage beans in the application context.
Click to reveal answer
beginner
What is the purpose of the @Bean annotation in a Spring Boot @Configuration class?
It tells Spring that the method will return an object that should be registered as a bean in the application context.
Click to reveal answer
intermediate
How do @Configuration and @Bean work together in Spring Boot?
<code>@Configuration</code> marks the class as a bean factory. Inside it, methods annotated with <code>@Bean</code> create and return beans that Spring manages.
Click to reveal answer
intermediate
Can a method annotated with @Bean have parameters? What happens if it does?
Yes, it can have parameters. Spring will automatically inject beans matching those parameter types when calling the method.
Click to reveal answer
intermediate
Why might you use @Configuration and @Bean instead of @Component?
Because @Configuration allows you to define beans with custom logic inside methods, giving more control over bean creation than simple @Component classes.
Click to reveal answer
What does the @Configuration annotation indicate in Spring Boot?
AA REST controller
BA method that returns a bean
CA component scanned automatically
DA class that defines bean methods
What does the @Bean annotation do?
AMarks a method to produce a bean
BMarks a class as a bean
CInjects a bean into a field
DDefines a REST endpoint
If a @Bean method has parameters, what happens?
ASpring ignores the parameters
BSpring injects matching beans as arguments
CIt causes a compilation error
DThe method runs without parameters
Which annotation would you use to create a bean with custom setup logic?
A@Component
B@Service
C@Bean inside @Configuration
D@Repository
What is the main difference between @Component and @Configuration?
A@Configuration classes can contain multiple @Bean methods
B@Component is for beans, @Configuration is for REST
C@Component classes cannot be scanned
DThere is no difference
Explain how @Configuration and @Bean work together in Spring Boot to create and manage beans.
Think about a class that acts like a factory for objects.
You got /4 concepts.
    Describe why you might choose to use @Bean methods inside a @Configuration class instead of just using @Component on a class.
    Consider when you want to write code to create the bean yourself.
    You got /4 concepts.