Is it possible to define a prototype bean, using XML config or annotation-based config such that I can get an instance of the bean with a custom parameter value? My use case is a message queue handler that makes API calls with different parameter values that are supplied in the inbound message.
In this case it seems I can do one of two things:
- Get an instance of my prototype-scope bean and then call setters to customize it to be specific to the inbound message.
- Construct a new instance of the bean class using a plain
new MyPrototypeBean()
and then call setters to customize the instance.
Perhaps a different way of wording my question is: What is the benefit of using a prototype-scope bean vs. using a simple Java constructor?