使用Spring R2DBC存储库时,我可以提供自己的自定义R2dbcEntityTemplate吗?

时间:2020-11-03 02:37:26

标签: spring spring-data-r2dbc r2dbc

我可以通过以下方式进行必要的调整:

@EnableR2dbcRepositories(repositoryBaseClass = BaseRepo::class)

但这太高了。本质上,我使用需要在R2dbcEntityTemplate.class级别完成的自定义行为覆盖了顶层方法,因此如果我可以提供自定义R2DBC团队模板,那就太好了。我尝试声明bean,但是由于我的代码是硬编码,所以它没有选择我的:

/*
 * (non-Javadoc)
 * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getTargetRepository(org.springframework.data.repository.core.RepositoryInformation)
 */
@Override
protected Object getTargetRepository(RepositoryInformation information) {

    RelationalEntityInformation<?, ?> entityInformation = getEntityInformation(information.getDomainType(),
            information);

    return getTargetRepositoryViaReflection(information, entityInformation,
            new R2dbcEntityTemplate(this.databaseClient, this.dataAccessStrategy), this.converter);
}

1 个答案:

答案 0 :(得分:0)

您可以使用

代替repositoryBaseClass

@ EnableR2dbcRepositories(repositoryFactoryBeanClass = MyR2dbcRepositoryFactoryBean.class)

然后在MyR2dbcRepositoryFactoryBean上,您可以使用方法setEntityOperations来设置自己的R2dbcEntityTemplate