Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
buzzerrookie opened this issue Sep 7, 2021 · 4 comments
Closed

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

buzzerrookie opened this issue Sep 7, 2021 · 4 comments
Labels
status: ideal-for-contribution An issue that a contributor can help us with status: superseded An issue that has been superseded by another type: enhancement A general enhancement

Comments

@buzzerrookie
Copy link

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 7, 2021
@wilkinsona
Copy link
Member

wilkinsona commented Sep 7, 2021

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.

@wilkinsona wilkinsona added the for: team-attention An issue we'd like other members of the team to review label Sep 7, 2021
@snicoll
Copy link
Member

snicoll commented Sep 7, 2021

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).

@wilkinsona
Copy link
Member

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

@wilkinsona wilkinsona changed the title H2ConsoleAutoConfiguration didn't print the correct h2 connection url under multiple datasources circumstance Log URLs for all DataSources when H2 Console is auto-configured Oct 4, 2021
@wilkinsona wilkinsona added type: enhancement A general enhancement and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Oct 4, 2021
@wilkinsona wilkinsona added this to the 2.x milestone Oct 4, 2021
@wilkinsona wilkinsona added the status: ideal-for-contribution An issue that a contributor can help us with label Oct 4, 2021
@snicoll
Copy link
Member

snicoll commented Oct 6, 2021

Closing in favor of PR #28204

@snicoll snicoll closed this as completed Oct 6, 2021
@snicoll snicoll added the status: superseded An issue that has been superseded by another label Oct 6, 2021
@snicoll snicoll removed this from the 2.x milestone Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ideal-for-contribution An issue that a contributor can help us with status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants