Returning Singleton beans depending on input in Spring

Clash Royale CLAN TAG#URR8PPPReturning Singleton beans depending on input in Spring
Let's say I have the following:
@Component
@NoArgsConstructor
public class ToolFactory {
public Tool getTool(String type) {
return StaticToolProvider.getTool(type);
}
}
If the tools can be screwdriver, hammer, or wrench, I want Spring to create Singleton beans for each, and return them when getTool() is called. I believe @Provides @Singleton would do this in Guice, but how could I do it here?
getTool()
@Provides @Singleton
I will only ever return a screwdriver, hammer, or wrench, but I don't want new prototype beans returned for every call. I only want 3 beans to only ever be created, but I want them created as
getTool() is called, or the existing Singleton returned if it exists.– radgokart
4 mins ago
getTool()
You have screwdriver, hammer bean which implements Tool?
– sajib
1 min ago
add more code and ask what you have and what you want
– sajib
1 min ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
give details. what you want to do
– sajib
6 mins ago