diff --git a/pandaria-db/src/main/java/com/github/jakimli/pandaria/configuration/DataSourcesConfiguration.java b/pandaria-db/src/main/java/com/github/jakimli/pandaria/configuration/DataSourcesConfiguration.java index f48217f..92eae70 100644 --- a/pandaria-db/src/main/java/com/github/jakimli/pandaria/configuration/DataSourcesConfiguration.java +++ b/pandaria-db/src/main/java/com/github/jakimli/pandaria/configuration/DataSourcesConfiguration.java @@ -3,6 +3,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; +import javax.annotation.PostConstruct; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; diff --git a/pandaria-db/src/main/java/com/github/jakimli/pandaria/domain/DataSources.java b/pandaria-db/src/main/java/com/github/jakimli/pandaria/domain/DataSources.java index 49ec173..3f76502 100644 --- a/pandaria-db/src/main/java/com/github/jakimli/pandaria/domain/DataSources.java +++ b/pandaria-db/src/main/java/com/github/jakimli/pandaria/domain/DataSources.java @@ -6,9 +6,11 @@ import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.stereotype.Component; +import javax.annotation.PostConstruct; import javax.sql.DataSource; import java.util.Map; +import static com.github.jakimli.pandaria.configuration.DataSourcesConfiguration.DEFAULT; import static com.google.common.collect.Maps.newHashMap; @Component @@ -45,4 +47,13 @@ private DataSource buildDataSource(DatasourceProperties property) { .password(property.getPassword()) .build(); } + + + @PostConstruct + public void validateAdditionalDataSourceName() { + if (configuration.getAdditional().stream() + .anyMatch(property -> DEFAULT.equalsIgnoreCase(property.getName()))) { + throw new RuntimeException(String.format("datasource name: '%s' is reserved", DEFAULT)); + } + } }