Results 1 to 4 of 4

Thread: Getting reference from property definition

  1. #1
    Join Date
    Feb 2006
    Posts
    26

    Default Getting reference from property definition

    In my app config I have;

    Code:
    <bean class="test">
      <property name="prop" ref="some.bean"/>
    </bean>
    At runtime I want to replace "some.bean" by "some.other.bean".
    So when "test" is used, it would be using "some.other.bean".

    To do this, I'm using InstantiationAwareBeanPostProcessorAdapter and method;

    Code:
    public PropertyValues postProcessPropertyValues(PropertyValues propertyValues,
    			PropertyDescriptor[] propertyDescriptors, Object bean, String beanName).
    Now, I have some special case here for which I need the original reference value instead of the actual referenced object.
    In other words, I want to retrieve "some.bean" as the actual name of the referenced bean.

    In the API I can get several things; I can get the property name (which is 'prop') I also can get the object reference to some.bean etc.
    But not the original ref. value before it was 'replaced' by the actual bean reference (some.bean)

    Is there a way to do this?

  2. #2
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    You can implement that via BeanFactoryPostProcessor. I.e. you can get necessary BeanDefinition object and check initial property string value.

  3. #3
    Join Date
    Feb 2006
    Posts
    26

    Default

    Ok thanks, that is indeed the solution.

    Is there also some processor which works on a higher level and allows to replace the "BeanRuntimeReference" of the BeanDefinition for a certain bean?

    This way I could pull everything on a higher level, I could use the BeanDefinition to extract the current reference, and then I could replace that reference with a new bean reference.

  4. #4
    Join Date
    May 2007
    Location
    Saint Petersburg, Russian Federation
    Posts
    1,189

    Default

    Quote Originally Posted by errorken View Post
    Ok thanks, that is indeed the solution.

    Is there also some processor which works on a higher level and allows to replace the "BeanRuntimeReference" of the BeanDefinition for a certain bean?

    This way I could pull everything on a higher level, I could use the BeanDefinition to extract the current reference, and then I could replace that reference with a new bean reference.
    The main thing here is the algorithm you want to use for bean metadata change. If it's ok to configure that statically you can use PropertyPlaceholderConfigurer or PropertyOverrideConfigurer. They both are BeanFactoryPostProcessor implementations.

    If you want to perform the process dynamically the only way to go is to implement simple BeanFactoryPostProcessor-based processor that allows to configure necessary rules at convenient way. That's really simple

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •