|
.collect(Collectors.toMap((e) -> e.getKey().toString(), Map.Entry::getValue)); |
I just upgraded our project from springboot 2.4.1 to 2.5.3. I am super exited, that there is support for AbstractRoutingDataSource now. Thank' and kudos for that!
Due to the update the health check now run's into an NPE which kills the whole application.
It happens because the entryset 'routingDataSource.getResolvedDataSources().entrySet()' contains null as a key.
We create our datasource like this:
@Bean
@Primary
public DataSource dataSource() {
final RoutingDataSource routingDataSource = new RoutingDataSource();
final DataSource primaryDataSource = buildDataSource("PrimaryHikariPool", primaryDataSourceProperties());
final DataSource replicaDataSource = buildDataSource("ReplicaHikariPool", replicaDataSourceProperties());
final Map<Object, Object> targetDataSources = new HashMap<>();
// HERE WE PUT IN OUR EVIL null KEY
targetDataSources.put(null, primaryDataSource);
targetDataSources.put(RoutingDataSource.Route.REPLICA, replicaDataSource);
routingDataSource.setTargetDataSources(targetDataSources);
routingDataSource.setDefaultTargetDataSource(primaryDataSource);
return routingDataSource;
}
It might be strange or even stupid to put 'null' as a key into a map, but the RoutingDataSourceHealthContributor shouldn't crash because of that anyway.
spring-boot/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthContributorAutoConfiguration.java
Line 130 in b65cc4d
I just upgraded our project from springboot 2.4.1 to 2.5.3. I am super exited, that there is support for AbstractRoutingDataSource now. Thank' and kudos for that!
Due to the update the health check now run's into an NPE which kills the whole application.
It happens because the entryset 'routingDataSource.getResolvedDataSources().entrySet()' contains null as a key.
We create our datasource like this:
It might be strange or even stupid to put 'null' as a key into a map, but the RoutingDataSourceHealthContributor shouldn't crash because of that anyway.