BLACK FRIDAY SALE – Unlock Up to 25% OFF on All Exam Prep! - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

VMware 2V0-72.22 Exam - Topic 11 Question 67 Discussion

Posted by Heike on Feb 08, 2025 at 06:53 PM

Refer to the exhibit.

How can a Spring Bean be created from this LegacySingleton class?

Suggested Answer: A

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
28 comments · newest first
MA
Matilda 12 months ago
Wait, is it really not possible without changing the constructor? That sounds odd!
ME
Merilyn 12 months ago
D seems like overkill, why modify the class?
JA
Jamal 1 year ago
C makes sense, can't create a bean with a private constructor.
ZA
Zana 1 year ago
I think B could work too, but it's not ideal.
MA
Margery 1 year ago
A is definitely the way to go!
KA
Kandis 1 year ago
I feel like modifying the LegacySingleton class is a bit too much for this question, so I would lean towards option A as well.
LY
Lynda 1 year ago
I practiced a similar question where we had to create a bean from a singleton class, and I think we called a method to get the instance, like in option A.
DE
Dell 1 year ago
I'm not entirely sure, but I remember something about needing a public constructor for Spring to create beans. Maybe option C is correct?
BR
Brandon 1 year ago
I think option A makes the most sense since we can use the singleton pattern to get the instance.
HO
Hollis 1 year ago
I think the answer is to call the LegacySingleton.getInstance() method from within a @Bean method. That way, I can return the existing singleton instance to the Spring context.
LE
Leonor 1 year ago
I'm a bit confused on this one. The question mentions modifying the LegacySingleton class, but I'm not sure if that's the best approach. I'll need to review the Spring Bean lifecycle and how to handle existing singletons.
CA
Carman 1 year ago
Okay, let's see. The key here is that the LegacySingleton class is a singleton, so I'll need to find a way to leverage that in the Spring context.
KE
Keneth 1 year ago
Hmm, this looks like a tricky one. I'll need to think carefully about the Spring Bean creation process and how it interacts with the LegacySingleton class.
MI
Mitsue 2 years ago
Hold up, did anyone else notice the exhibit is just a picture of a dog? I'm so distracted now, I forgot the question. What were we talking about again?
FI
Filiberto 2 years ago
↳ replying to Mitsue
D) Modify the LegacySingleton class by adding the @Autowired annotation to the instance variable.
GE
Genevieve 2 years ago
↳ replying to Mitsue
C) It is not possible without modifying the LegacySingleton class, the constructor must be public.
WI
Wilda 2 years ago
↳ replying to Mitsue
B) Return an instance of LegacySingleton using the new keyword from a @Bean method.
AN
Anthony 2 years ago
↳ replying to Mitsue
A) Call LegacySingleton.getInstance() from within a @Bean method and return the instance.
BE
Becky 2 years ago
You know, if this was a real-world problem, I'd just rewrite the whole darn thing from scratch. Screw legacy code! Option D is my pick.
JO
Joana 2 years ago
C'mon, really? We can't modify the class? That's just lazy. Option B all the way!
SE
Selma 2 years ago
↳ replying to Joana
You're right, we can't modify the class. The correct answer is A) Call LegacySingleton.getInstance() from within a @Bean method and return the instance.
MA
Margurite 2 years ago
↳ replying to Joana
Option B is not the correct way to create a Spring Bean from this LegacySingleton class.
MY
Myrtie 2 years ago
I think option A is the way to go. Calling getInstance() from a @Bean method seems like the cleanest approach.
HE
Helene 2 years ago
↳ replying to Myrtie
User2: Yes, calling getInstance() from a @Bean method is the cleanest way to create a Spring Bean from LegacySingleton.
AN
Annita 2 years ago
↳ replying to Myrtie
User1: I agree, option A is the most appropriate solution here.
SK
Skye 2 years ago
But wouldn't adding the @Autowired annotation to the instance variable also work? That's option D.
AN
Annamaria 2 years ago
I disagree, I believe the answer is C. We need to modify the LegacySingleton class to make the constructor public.
SK
Skye 2 years ago
I think the answer is A, because we can call LegacySingleton.getInstance() from a @Bean method.
0/2000 characters

Save Cancel