I'm using two datasources (Oracle + h2) in my spring boot project. I configure them manually in my configuration class, and the Oracle Datasource is annotated with Primary. When my project starts, the H2ConsoleAutoConfiguration prints out its log: o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:oracle:thin:@xxx' I replace my oracle ip and sid with xxx.

The expected behavior is H2ConsoleAutoConfiguration should print jdbc:h2:mem:xxx instead of jdbc:oracle:thin.

I delve into H2ConsoleAutoConfiguration.java and find the following code:

dataSource.ifAvailable((available) -> {
    try (Connection connection = available.getConnection()) {
        logger.info("H2 console available at '" + path + "'. Database available at '"
                + connection.getMetaData().getURL() + "'");
    }
    catch (Exception ex) {
        // Continue
    }
});

Is it better to check the connection URL starts with jdbc:h2 such that the log can print the correct h2 database connection?

Spring Boot version: 2.4.5 my sample project: multi-datasource.zip

Comment From: wilkinsona

Thanks for the suggestion. H2's console isn't limited to H2 databases so, if it's only going to log the connection info for one DataSource, I think it makes sense for it to be the one that's primary.

We could consider logging the connection details for every DataSource in the context instead. Flagging for team attention to see if the team thing that's a change worth making.

Comment From: snicoll

Yeah, I think a log along those lines could be useful. I need to be constantly reminded that the H2 console works also with another database (it's just counter intuitive for me).

Comment From: wilkinsona

This has come up in the past but I don't think an issue was ever raised for it.

Comment From: snicoll

Closing in favor of PR #28204