
Originally Posted by
Jörg Heinicke
Do you have set up a map of data sources and pass it to your RoutingDataSource? The EnvironmentType returned by determineCurrentLookupKey() is used to lookup the data source in this map.
Jörg
I understand that. But I was wondering how the current datasource value is handled. The map is only a list of the different datasources, but what if datasource 4 is the one being used. I recon it is the ThreadLocal variable which knows which datasource is the current one. I did not understand how AbstractRoutingDataSource was using the ThreadLocal to find this value. I could not see any threading references in the source to look this value up.
My dataSource bean
Code:
<bean id="dataSource" class="datasource.RoutingDataSource">
<property name="targetDataSources">
<map key-type="datasource.EnvironmentType">
<entry key="PP2" value-ref="dataSourcePP2" />
<entry key="PP3" value-ref="dataSourcePP3" />
<entry key="PP4" value-ref="dataSourcePP4" />
<entry key="ST1" value-ref="dataSourceST1" />
<entry key="ST2" value-ref="dataSourceST2" />
<entry key="ST3" value-ref="dataSourceST3" />
<entry key="ST4" value-ref="dataSourceST4" />
</map>
</property>
<property name="defaultTargetDataSource" ref="dataSourcePP1" />
</bean>
And I have defined several beans for the different datasources
Code:
<bean id="parentDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" abstract="true">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="username" value="******"/>
<property name="password" value="******"/>
</bean>
<bean id="dataSourcePP1" parent="parentDataSource">
<property name="url" value="jdbc:oracle:thin:@****"/>
</bean>
....