Skip to content

Log URLs for all DataSources when H2 Console is auto-configured #27881

Closed
@buzzerrookie

Description

@buzzerrookie

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions