If a class is annotated with @Component, what should be done to have Spring automatically detect the annotated class and load it as a bean? (Choose the best answer.)
Suggested Answer: C, D
Get Premium 2V0-72.22 Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
27 comments · newest first
HE
Heike
12 months ago
So, @ComponentScan is a must? That’s new to me!
BU
Buck
12 months ago
@Scope isn't necessary for detection, just saying.
AN
An
1 year ago
Wait, I thought @Bean was enough?
CH
Chan
1 year ago
Totally agree, B is the way to go!
DA
Dante
1 year ago
You need @ComponentScan to pick it up!
DA
Dahlia
1 year ago
I’m confused about the @Scope part. I don’t think it’s necessary for Spring to detect the class, but I could be wrong.
LI
Lillian
1 year ago
I feel like specifying a valid bean name in @Component could be important, but it doesn't seem like the main requirement for detection.
JA
Jarvis
1 year ago
I remember practicing a question like this, and I think option B is the right choice because it relates to scanning for components.
IZ
Izetta
1 year ago
I think we need to use @ComponentScan to make sure Spring picks up the class, but I'm not entirely sure if that's the only thing we need.
LY
Lynna
1 year ago
I'm feeling pretty confident about this one. The answer is definitely B. The @ComponentScan annotation is what tells Spring to automatically detect and load the @Component annotated classes. Simple as that!
RO
Robt
1 year ago
Okay, I think I've got this. The key is to make sure the @ComponentScan annotation is properly configured to scan the package where the @Component annotated class is located. That should do the trick.
AS
Ashlee
1 year ago
Hmm, I'm a bit confused on this one. I know the @Component annotation is used to mark a class as a Spring bean, but I'm not sure what else needs to be done to have it automatically loaded. I'll have to review my notes on Spring configuration.
MI
Misty
1 year ago
I'm pretty sure the answer is B. We need to have a valid @ComponentScan annotation in the Java configuration to get Spring to automatically detect the @Component annotated class.
CO
Cornell
2 years ago
Hmm, I'm not sure. I was leaning towards D, but now I'm second-guessing myself. Isn't the @Bean annotation used for manually registering beans?
EM
Emilio
2 years ago
I disagree, I think the correct answer is C. Specifying a valid @Scope for the class is necessary for Spring to manage the bean's lifecycle.
JE
Jerry
1 year ago
I'm not sure, but I think C is also important for managing the bean's lifecycle.
LE
Leandro
1 year ago
I agree with the first user. B is the correct answer.
BR
Brunilda
1 year ago
No, I believe the answer is D. You should ensure a valid @Bean for the class is specified.
LU
Lucille
1 year ago
I think the correct answer is B. You need to specify a valid @ComponentScan annotation in the Java configuration.
LA
Lawrence
2 years ago
I thought the correct answer was A. Specifying a valid bean name in the @Component annotation is important for Spring to detect the class as a bean.
KI
Kip
2 years ago
The correct answer is B. The @ComponentScan annotation is used to specify the package(s) where Spring should scan for annotated components.
KI
Kizzy
1 year ago
C) Ensure a valid @Scope for the class is specified.
CH
Chaya
1 year ago
B) Ensure a valid @ComponentScan annotation in the Java configuration is specified.
KE
Kelvin
2 years ago
A) Ensure a valid bean name in the @Component annotation is specified.
QU
Quentin
2 years ago
I'm not sure about that. I think it might also be A) Ensure a valid bean name in the @Component annotation is specified.
TE
Telma
2 years ago
I agree with Lina. @ComponentScan is used to specify the base packages to scan for components.
LI
Lina
2 years ago
I think the answer is B) Ensure a valid @ComponentScan annotation in the Java configuration is specified.