I have several XA datasources I need to configure within a Spring application context that I use for integration testing inside of Maven. They look like this:
<bean id="sbeH2XADataSource" class="org.h2.jdbcx.JdbcDataSource">
<property name="URL" value="$DS{hibernate.connection.url}" />
<property name="user" value="$DS{hibernate.connection.username}" />
<property name="password" value="$DS{hibernate.connection.password}" />
</bean>
<bean id="sbeMySQLXADataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource">
<property name="URL" value="$DS{hibernate.connection.url}" />
<property name="user" value="$DS{hibernate.connection.username}" />
<property name="password" value="$DS{hibernate.connection.password}" />
</bean>
Ideally, I’d use Maven filtering to set the bean class, but Spring doesn’t like that (at least not Spring tooling in Eclipse). I really would like to avoid making both beans and rather just make the one. In the event I have to make both and use only one, how does one create a bean “ref” that is dynamic?
You can also use a property place holder for the ref value and configure which bean to use from your properties file.