Closed bobbyrne01 closed 1 year ago
Hi @bobbyrne01!
The library doesn't rely on the mentioned properties, it works at the level of data source beans. So you don't have to worry about your application.properties
, it's fine as is. But what is a problem is the custom implementation of MultiTenantConnectionProvider
. Because the implementation operates with spring.datasource.*
variables instead of the data source beans. That's why a test data source cannot be correctly propagated to hibernate and maybe other components. So you have to get rid of the MultiTenantConnectionProviderImpl
(at least for tests, using spring profile), or replace it with a test implementation referring to a data source. Check out the example below.
@Component
public class TestConnectionProvider extends AbstractMultiTenantConnectionProvider {
@Autowired private DataSource dataSource;
@Override
protected ConnectionProvider getAnyConnectionProvider() {
return selectConnectionProvider("");
}
@Override
protected ConnectionProvider selectConnectionProvider(String tenantIdentifier) {
DatasourceConnectionProviderImpl connectionProvider = new DatasourceConnectionProviderImpl();
connectionProvider.setDataSource(dataSource);
return connectionProvider;
}
}
Thanks @tomix26 I've used a test impl as you suggested and unit test is working now.
Appreciate the quick and helpful response!
By default my application will acquire db details from
application.properties
on app start-up, which is part of Hibernate's startup processing.I'm wondering what host:port should be set in the application's properties in order for this library to handle connection requests like this? If it is even possible?
Configuration:
Error:
The Java test:
Where the exception originates from: