【发布时间】:2020-02-04 19:15:13
【问题描述】:
我正在使用spring boot 版本2.1.9 和spring-data。我已经定义了一个存储库
interface TokenRepository : CrudRepository<Token, Long> {
fun findBySubject(subject: String): Token?
}
出于测试目的,我创建了 CrudRepository 的抽象假冒,它实现了 CrudRepository 中的所有方法:
abstract class RepositoryFake<T> : CrudRepository<T, Long> {
...
override fun existsById(id: Long): Boolean {
...
}
override fun deleteById(id: Long) {
...
}
override fun findById(id: Long): Optional<T> {
...
}
...
}
现在,当我创建扩展 RepositoryFake 的 TokenRepository 的实现时
class TokenRepositoryFake : RepositoryFake<Token>(), TokenRepository {
override fun findBySubject(subject: String): Token? {
...
}
}
编译器抱怨TokenRepositoryFake 不是抽象的,并且它没有实现方法existsById、deleteById 和findById,尽管这些方法在RepositoryFake 中实现。它不会抱怨CrudRepository 中定义的其他方法。为什么编译器抱怨缺少方法而不是所有其他方法?
错误信息示例:
Class 'TokenRepositoryFake' is not abstract and does not implement abstract member public abstract fun deleteById(p0: Long): Unit defined in my.repositories.TokenRepository
【问题讨论】:
标签: kotlin spring-data