Wouldn't it work to have multiple datasourcesdata sources defined, and depending on your request, change to the one with the correct schema?
spring.datasource.url = jdbc:oracle:thin:@//maui:1521/xe
spring.datasource.username = schema1
spring.datasource.password = ...
spring.datasource2.url = jdbc:oracle:thin:@//maui:1521/xe
spring.datasource2.username = schema2
spring.datasource2.password = ..
@Bean
@Primary
@ConfigurationProperties(prefix="spring.datasource")
public DataSource schema1() {
return DataSourceBuilder.create().build();
}
@Bean
@ConfigurationProperties(prefix="spring.datasource2")
public DataSource schema2() {
return DataSourceBuilder.create().build();
}
Otherwise youyou'd need to kill & re-create the connection to keep using single datasourcethe singular data source, but that would be really slow for your application since it would need reconnecting again and again. It would be better for you to use some NoSQL database to achieve this sorta dynamic data storage.