- 
                Notifications
    You must be signed in to change notification settings 
- Fork 41.6k
Description
Right now DataSourceInitializer runs regardless of the fact that we've auto-configured a DataSource or a custom one is available. If more than one is available, this currently throws a low-level exception because we expect a primary.
We have plans to change the last bit in 2.0 but I think it is confusing that we apply something datasource related on something that we haven't auto-configured. After all things defined in spring.datasource (in DataSourceProperties) should only be taken into account if we configure the DataSource.
The side effect is that if we do this explicitly, we have the guarantee the DataSource is initialized and ready to be used once we expose it in the context. Right now we use a BPP for that and it causes hard to track issues such as #9394
The purpose of this issue is to:
- Create a public pojo-based API that initializes a DataSource. It should be super easy to grab an instance of such object based onDataSourceProperties
- Replace the auto-configuration to create that object and migrate the database. We have DataSourceConfiguration#createDataSourcethat has all that we need to share that logic. We'd also need to updateEmbeddedDataSourceConfigurationso it would be nice if we could easily migrate aDataSourcebased on aDataSourceand aDataSourcePropertiesinstances
If someone is willing to initialize a custom DataSource then they'll have to do the same thing but at least it will be explicit.