The default behaviour of JdbcRepositoriesAutoConfiguration does not allow an application to start if the datasource connection is not valid. It's because the DefaultDialectProvider needs a valid connection in order to auto-detect and provide a Dialect. Of course, this behaviour can be changed by implementing a JdbcDialectProvider or by overwriting AbstractJdbcConfiguration.jdbcDialect(NamedParameterJdbcOperations), as specified in the documentation. Both solutions involve writing code, though.

A proposed solution for configuring directly a Dialect is to have a new property. For example: spring.data.jdbc.repositories.dialect, similar with the JPA property spring.jpa.database-platform

Comment From: wilkinsona

There's some similarity to https://github.com/spring-projects/spring-boot/issues/28842. Even without a property, we may be able to use Boot's DatabaseDriver to provide the dialect without relying upon a connection. However, with Spring Data JDBC, I'm not sure how helpful this would be or if it would allow the application to start while the database is down.

Comment From: schauder

Except for the current Dialect detection Spring Data JDBC shouldn't access the database before it actually gets asked to load or persist something.

Comment From: snicoll

As far as I can see, the dialects supported by Spring Data JDBC are hard-coded in the implementation that relies on the connection. We'll have to write a mapping from DatabaseDriver to the dialect implementation but it feels to me that an enum in Spring Data JDBC would be beneficiary. For instance a protected DialectId dialectId() in AbstractJdbcConfiguration that would return null and that can be overridden by configuration?

There are also some specific logic for MySQL that requires additional metadata so I am not sure what we should be doing here.

Comment From: wilkinsona

I'd envisaged an override of AbstractJdbcConfiguration.jdbcDialect(NamedParameterJdbcOperations) in SpringBootJdbcConfiguration that returns the dialect that has been configured via a property. However, I'd overlooked the complexity of the MySQL dialect that needs an IdentifierProcessing instance and, therefore, doesn't lend itself to property-based configuration.

I don't think there's anything that we can do in Boot without Spring Data JDBC provided a simpler dialect configuration mechanism. @mcnuca, if this is something that you'd still like to see, please open a Spring Data JDBC issue and comment here with a link to it.

Comment From: mcnuca

@wilkinsona I have created the issue because a Spring Boot application using Spring Data JDBC (and no custom code) does not start if the database is unavailable. The request is very similar with #4779. I'm sorry if I was not clear enough in the original comment. Setting up a Dialect with a property was just a proposal I came up with, but not a request. The problem is still there and maybe it can be solved in a different way.

Comment From: wilkinsona

Thanks for the clarification. In that case, I'll close this as a duplicate of #4779. If you're interested in pursuing a Spring Data JDBC-specific solution, please open a Spring Data JDBC issue as I don't think we can do anything in Boot without a change in Data JDBC.

Comment From: mcnuca

@wilkinsona The issue has been originally opened in Spring Data JDBC and transferred later to Spring Boot by @odrotbohm

Comment From: wilkinsona

I realise that. The issue as written was clearly about Spring Boot as it mentioned Boot's JdbcRepositoriesAutoConfiguration in its opening sentence so it's entirely understandable that Ollie transferred it to us to investigate.

After the investigation above, it's become clear that there's nothing that we can do for Spring Data JDBC specifically without a change in Spring Data JDBC. I am recommending that you open a Spring Data JDBC issue that doesn't mention Boot at all but instead proposes making it easier to configure Data JDBC's dialect for everyone, not just Spring Boot's users. For example, if the mechanism that maps between String IDs and dialect instances was public, Spring Data JDBC could be passed an ID and then use the corresponding dialect without need for a Connection to the database. Spring Boot could then add a property that's used to supply the ID that's passed into Spring Data JDBC to configure its dialect.