How can I qualify an autowired property with a variable from a config file using annotations?
Posted
by
jiggy
on Stack Overflow
See other posts from Stack Overflow
or by jiggy
Published on 2011-01-14T22:49:03Z
Indexed on
2011/01/14
22:53 UTC
Read the original article
Hit count: 185
My specific problem is that I have configured two beans that implement the same interface and I have a third bean that has a property of that interface's type. I inject the property using a config property. So, assuming RemoteDataSource and LocalDataSource implement IDataSource and dao1 has a property of type IDataSource, my XML config might look like this:
<bean id="datasource1" class="com.foo.RemoteDataSource">
<property name="url">${url}</property>
</bean>
<bean id="datasource2" class="com.foo.LocalDataSource">
<property name="path">${filepath}</property>
</bean>
<bean id="dao1" class="com.foo.MyDAO">
<property name="dataSource">${datasource}</property>
</bean>
With url, filepath and datasource being defined in an included properties file. We are now making a push for annotation-driven configuration and I'm not sure how to annotate my dao to put the data source configured in the property file. I want to do something like this, but it is evidently not allowed:
@Autowired
@Qualifier("${datasource}")
public void setDataSource(IDataSource datasource) {...}
© Stack Overflow or respective owner