I have question about the need of using @configurable. I have gone through the blog that explains how to use @configurable. But the question that comes to my mind is, what can be the scenario when we need to use @configurable. I can think of two scenarios where it can be useful
-
In a legacy project, when we are already making any bean with new operator and we want to make it spring managed.
-
In a new project, we want to enforce that even if developer makes the bean with new operator, still it is spring managed.
Otherwise for new beans we can always declare them in applicationContext.xml and I do not see any need to declare them @configurable.
Please let me know if above understanding is correct or if I am missing something.
UPDATE:- Basically as per my understanding configurable is generally used to inject dependency when creating the object with new operator. But why would i be creating the object with new operator when i am using spring
@Configurableannotation is meant for injecting dependencies indomain-drivenapplications. That means, in such applications, the domain objects interact with each other to perform a certain operation.Take the following example:
In an invoicing application, the
Invoiceclass provides a constructor to create it, then it has methods to validate, and finally persist it. Now, to persist the invoice, you need aDAOimplementation available within the invoice. This is a dependency you would like to be injected or located. With Spring’s@Configurable, whenever an invoice is created using thenewoperator, the appropriate DAO implementation will get injected and can be used for all persist operations.I had a more realtime scenario where I used
@Configurableannotation as described here.