我有一个简单的多数据库设置来尝试使用 r2dbc 进行多数据库配置。但是,它没有按预期工作,它总是使用第一个数据库。
@Configuration
@EnableR2dbcRepositories(databaseClientRef="postgreDbClient". basePackages={"com.x.y.repo.postgresql"})
public class PostgreSqlConfiguration extends AbstractR2dbcConfiguration{
@Bean(name="postgresqlConnectionFactory")
ConnectionFactory connectionFactory(){
return ConnectionFactories.get("r2dbc:postgresql://<host>:5432/<database>");
}
@Bean(name="postgreDbClient")
DatabaseClient databaseClient(){
return DatabaseClient.create(this.connectionFactory());
}
}
@Configuration
@EnableR2dbcRepositories(databaseClientRef="mssqlDbClient". basePackages={"com.x.y.repo.mssql"})
public class PostgreSqlConfiguration extends AbstractR2dbcConfiguration{
@Bean(name="mssqlConnectionFactory")
ConnectionFactory connectionFactory(){
return ConnectionFactories.get("r2dbc:mssql://<host>:1433/<database>");
}
@Bean(name="mssqlDbClient")
DatabaseClient databaseClient(){
return DatabaseClient.create(this.connectionFactory());
}
}
com.x.y.repo.postgresql
-EmployeeRepository.java
-DepartmentRepository.java
com.x.y.repo.mssql
-PuchaseRepository.java
-SalesRepository.java
public interface EmployeeRepository extends R2dbcRepository<Employee, Integer>{
}
public interface PuchaseRepository extends R2dbcRepository<Purchase, Integer>{
}
以上是我的代码的简单表示。我的请求总是去 Postgresql,尽管 basepackage 是为 mssql 包配置的com.x.y.repo.mssql