spring-boot - Spring Boot应用中的接口继承问题
问题描述
我编写了一个小型 Spring Boot 应用程序,它有两种使用配置文件的不同类型的存储库;JpaRepository
和MongoRepository
。我创建了一个名为 ' common
' 的包,其中保存了包含常用方法的接口。然后我在我的 jpa 和 mongo 存储库中扩展这些接口。然而,这些通用接口也扩展了自定义存储库接口,其中包含以 mongo 和 jpa 方式具有自定义实现的方法。
这是我的存储库包结构:
+----common
-----------CommonExampleRepository.java
+----------custom
-----------------CommonExampleRepositoryCustom.java
+----------mongo
-----------------ExampleRepositoryCustomImpl.java
+----------sql
-----------------ExampleRepositoryCustomImpl.java
+----mongo
--------ExampleRepositoryMongo.java
+----sql
--------ExampleRepositorySql.java
这是一个通用存储库的样子
@NoRepositoryBean
public interface CommonRepository extends BaseRepository<EntityExample>, CommonExampleRepositoryCustom {
//some methods here
}
这是我的 jpa 特定存储库(mongo 也是如此):
@Profile("sql")
@Primary
public interface ExampleRepositorySql extends CommonRepository,
JpaRepository<EntityExample, ID> {
}
我希望这个存储库能够工作,因为CommonRepository
extends CommonExampleRepositoryCustom
。然而,事实并非如此。一旦我运行应用程序,它就会显示此错误:
org.springframework.data.mapping.PropertyReferenceException: No property xxx found for type EntityExample!
我还通过CommonRepositoryCustom
像这样扩展 sql 存储库中的 来临时修复它:
@Profile("sql")
@Primary
public interface ExampleRepositorySql extends CommonRepository,
CommonExampleRepositoryCustom
JpaRepository<EntityExample, ID> {
}
但这根本感觉不对,因为我也在扩展CommonExampleRepositoryCustom
,CommonRepository
否则它不起作用。
有些东西告诉我这与包结构有关,但我不太确定。我尝试了多种组织它们的方法,但没有任何效果。任何帮助,将不胜感激!
解决方案
推荐阅读
- python - 在 Django ORM 中按列表过滤连接字段
- wso2 - 在 wso2 身份服务器 saml 中,如何禁用 jsession id
- angular - 打字稿:从联合类类型中获取独家成员
- reactjs - React hook:如何在特定时间更新组件
- javascript - 如何在 discord.js 中获取不和谐服务器的名称和图片
- python - 如果内置文件 sprite.py 出错怎么办?
- javascript - Node js FileHandle读取方法抛出无效参数错误
- r - 在ggplot2中手动更改形状将颜色从实心变为轮廓?
- javascript - npm 无法安装全局包?
- android - MaterialDatePicker 很慢