Hi, https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.html#setTargetDataSources-java.util.Map-

it accepts Map but why is the second type an Object? Should not it be an interface DataSource? The method determineTargetDataSource map to this type anyway and cast exceptions may be throws if someone passes some other object.

Questions are:

  1. Is it save to assign Map to Map
  2. Why to accept argument with raw Object type rather then DataSource

Comment From: jhoeller

There's a note on it in the javadoc: The mapped value can either be a corresponding DataSource instance or a data source name String (to be resolved via a DataSourceLookup). So this is intentionally abstracted, even beyond DataSource/String since subclasses may implement the resolveSpecifiedDataSource template method in a custom way.

The determineTargetDataSource method operates on resolvedDataSources - a different data structure where the values are actual resolved DataSource instances, as returned from the above-mentioned resolveSpecifiedDataSource.