2V0-72.22PSE · Question #25
Which two statements are true regarding bean creation? (Choose two.)
The correct answer is B. A Spring bean can be implicitly created by annotating the class with @Component and using D. A Spring bean can be explicitly created using @Bean annotated methods within a Spring. B is correct because annotating a class with @Component (or its specializations like @Service, @Repository, @Controller) enables implicit bean creation - Spring's component scan automatically detects and registers these classes as beans without any manual wiring code. D is…
Question
Which two statements are true regarding bean creation? (Choose two.)
Options
- AA Spring bean can be explicitly created by annotating methods or fields by @Autowired.
- BA Spring bean can be implicitly created by annotating the class with @Component and using
- CA Spring bean can be implicitly created by annotating the class with @Bean and using the
- DA Spring bean can be explicitly created using @Bean annotated methods within a Spring
- EA Spring bean can be explicitly created by annotating the class with @Autowired.
How the community answered
(43 responses)- A2% (1)
- B88% (38)
- C2% (1)
- E7% (3)
Explanation
B is correct because annotating a class with @Component (or its specializations like @Service, @Repository, @Controller) enables implicit bean creation - Spring's component scan automatically detects and registers these classes as beans without any manual wiring code. D is correct because @Bean annotated methods inside a @Configuration class represent explicit bean creation - you write a method that returns the object, and Spring registers the return value as a managed bean.
Why the distractors fail:
- A & E are wrong because
@Autowiredis strictly for injecting (consuming) existing beans, never for creating them. It wires dependencies, it doesn't define them. - C is wrong because
@Beanbelongs on methods inside a@Configurationclass, not on the class itself. Placing@Beanon a class is not valid usage.
Memory tip: Think of the split as "Component = Come find me" (implicit, Spring scans and discovers it) vs. "@Bean method = I'll build it myself" (explicit, you write factory code). @Autowired is always the consumer, never the creator - if an answer says @Autowired creates a bean, it's a trap.
Topics
Community Discussion
No community discussion yet for this question.