May 31st, 2006, 04:26 AM
Initializing the Bean with Parameter obtained at runtime
I need to initiliaze a bean with 3 parameters. When i'm initializing the bean, if i specify the parameters in the configuration, Container creates this object at initializaiton time.
Basically this bean should be injected in other service beans where the initialization parameters changes from service to service. So i want to define the bean for each service, whenever the bean is injected into the service. Out of the three initilization parameters, 2 parameters are constants defined for that service, but the third object is an object created by a Facade before this service. Basically i want to introduce an interceptor( bean i'm talking about ) between the Facade and this service. But for each service, the interceptor should be intialized with a User object created by Facade. So only at the runtime the bean should be populated with the User object generated from Facade.
How to play with the Configuraiton to achieve this?
May 31st, 2006, 08:25 AM
Not sure if I understand it correctly, but for runtime initialization of beans maybe the code I posted here might be helpful.
May 31st, 2006, 09:08 PM
I wonder if you can define those two standard properties, not with the bean they will ultimately be applied to, but with each Service in your configuration file. Next, when your Service is created, you then initialize the bean with the two parameters that you have defined for the Service in the config file.
To do the bean initialization, have your Service class implement InitializingBean, and do this configuration of your bean within the afterPropertiesSet() method that this interface requires. (As for the third Facade-created object, I'm assuming the object created by the Facade will be available at the time aPS() is called so the bean can be initialized with this object as well.)