Skip to content

Commit

Permalink
prevent use specify datasource name as default in configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
JakimLi committed Mar 4, 2020
1 parent 3846a9c commit 45fa6d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
}
}
}

0 comments on commit 45fa6d2

Please sign in to comment.