1

I have a bean config file as follows

<bean id="myFactory" class="com.public.Factory">
    <property name="dataSourceAdaptor" ref="${value.from.property file}Adaptor" />
</bean>

How do i achieve this.

I added the following to top of the config file

<util:properties id="myProperties" location="classpath:app.properties"/>

and then tried to refer to the value using ${} but i get an error stating ${value.from.property file}Adaptor is not a valid bean

I cannot put the whole name (xyzAdaptor) in the property file as the value in the property file is an institution and there are multiple adaptors for each institution.

for example xzyDisplayAdaptor, xyzProductAdaptor, xyzDatasourceAdaptor

The xyz client can change to say abc client and i want to be able to change the value in property file to abc and all the abc related beans will be injected.

1
  • How about using a FactoryBean that reads from the properties and returns the respective adaptor? Commented Apr 1, 2014 at 15:55

2 Answers 2

1

The util:properties tag is used to create an instance of java.util.Properties. I think what you need is a PropertyPlaceholderConfigurer. e.g.,

<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" scope="singleton">
           <property name="searchSystemEnvironment" value="true" />
           <property name="ignoreResourceNotFound" value="true" />
           <property name="locations">
                <list>
                    <value>classpath:app.properties</value>
                </list>
            </property>
</bean>
Sign up to request clarification or add additional context in comments.

Comments

1

Try this with Spel:

    <util:properties id="myProperties" location="classpath:app.properties"/>

    <bean id="myFactory" class="com.public.Factory">
        <property name="dataSourceAdaptor" ref="#{'${value.from.property file}'+'Adaptor'}" />
    </bean>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.