NEW: Ovverride service objects with DatabaseConfig.putServiceObject

This commit is contained in:
Roland Praml committed 2022-10-25 10:28:55 +02:00
1 parent 7152cf656b
commit f8c6a3c960
6 files changed
+87 -7

No files matched your search

@@ -307,7 +307,10 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
*/
public void start() {
if (config.isRunMigration() && TenantMode.DB != config.getTenantMode()) {
final AutoMigrationRunner migrationRunner = ServiceUtil.service(AutoMigrationRunner.class);
AutoMigrationRunner migrationRunner = config.getServiceObject(AutoMigrationRunner.class);
if (migrationRunner == null) {
migrationRunner = ServiceUtil.service(AutoMigrationRunner.class);
}
if (migrationRunner == null) {
throw new IllegalStateException("No AutoMigrationRunner found. Probably ebean-migration is not in the classpath?");
}
@@ -117,7 +117,10 @@ final class InitDataSource {
* Attach DataSourceAlert via service loader if present.
*/
private void attachAlert(DataSourceConfig dsConfig) {
DataSourceAlertFactory alertFactory = ServiceUtil.service(DataSourceAlertFactory.class);
DataSourceAlertFactory alertFactory = config.getServiceObject(DataSourceAlertFactory.class);
if (alertFactory == null) {
alertFactory = ServiceUtil.service(DataSourceAlertFactory.class);
}
if (alertFactory != null) {
dsConfig.setAlert(alertFactory.createAlert());
}
@@ -144,7 +144,12 @@ public final class InternalConfiguration {
}
private <S> S service(Class<S> cls) {
return ServiceUtil.service(cls);
S service = config.getServiceObject(cls);
if (service != null) {
return service;
} else {
return ServiceUtil.service(cls);
}
}
private List<XmapEbean> readExternalMapping() {
@@ -111,7 +111,10 @@ public final class DefaultTypeManager implements TypeManager {
}
private void loadGeoTypeBinder(DatabaseConfig config) {
final GeoTypeProvider provider = ServiceUtil.service(GeoTypeProvider.class);
GeoTypeProvider provider = config.getServiceObject(GeoTypeProvider.class);
if (provider == null) {
provider = ServiceUtil.service(GeoTypeProvider.class);
}
if (provider != null) {
geoTypeBinder = provider.createBinder(config);
}