Dan Lipofsky opened SPR-16619 and commented
H2EmbeddedDatabaseConfigurer
is not public. So I can't extend it, and even if I could EmbeddedDatabaseBuilder
does not have a pass-through method to set the configurer on the underlying EmbeddedDatabaseFactory
.
All I really want to do is change the URL flags in H2EmbeddedDatabaseConfigurer
but there is no way to do it.
Please please add a pass-through method to the builder to set the configurer on the factory and also make the existing configurers public.
Affects: 4.3.13, 5.0.4
Comment From: snicoll
I can see how setDatabaseType
and setDatabaseConfigurer
are trumping each other. Even the factory that gets the configurer is private so there's not much we can do here with the current arrangement. When a connection pool is available, Spring Boot is doing its own thing, see org.springframework.boot.jdbc.EmbeddedDatabaseConnection
, which offers the usual customizations. If no connection pool is around, it defers to this infrastructure but then there is no way to tune the properties of the connection.
I don't really see why this has to be so private to be honest. We'd have to spike before opening things a little.
@wilkinsona is there anything particular that Spring Boot could use when a connection pool is not available? Or perhaps something that would make it common with the connection pool use case?
Comment From: wilkinsona
It's hard to say with any certainty because, as far as I can remember, no one's asked for Boot's purely embedded (no connection pool) case to be more configurable. That may well be due to a connection pool being on the classpath the vast majority of the time.
The URLs in Boot's EmbeddedDatabaseConnection
match those in the various sub-classes of AbstractEmbeddedDatabaseConfigurer
. That perhaps opens the door to allowing Boot to pass the URL down into the builder somehow. Things would then continue to work as they do today by default and spring.datasource.url
– which is currently ignored in the purely embedded case – could be set for customization purposes.
Comment From: snicoll
Thanks Andy. I did try something which gives some flexibility to call the configurer with whatever arguments we want and tune things after if necessary, see https://github.com/snicoll/spring-framework/commit/f52ac3a4a79f045e183b2a471a8678611abd3821
This can be used as follows:
this.factory.setDatabaseConfigurer(EmbeddedDatabaseConfigurers.customizeConfigurer(
EmbeddedDatabaseType.H2, defaultConfigurer ->
new EmbeddedDatabaseConfigurerDelegate(defaultConfigurer) {
@Override
public void configureConnectionProperties(ConnectionProperties properties, String databaseName) {
super.configureConnectionProperties(properties, "custom-db-name");
}
}));
Comment From: sbrannen
Related Issues
-
13491
-
16037
-
17215