如何解决使用Spring R2DBC存储库时,我可以提供自己的自定义R2dbcEntityTemplate吗?
我可以通过以下方式进行必要的调整:
@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);
}
解决方法
您可以使用
代替repositoryBaseClass@ EnableR2dbcRepositories(repositoryFactoryBeanClass = MyR2dbcRepositoryFactoryBean.class)
然后在MyR2dbcRepositoryFactoryBean上,您可以使用方法setEntityOperations
来设置自己的R2dbcEntityTemplate
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。