Scala:Spring 数据存储库中的 Int id

Scala: Int id in Spring Data Repository

我正在尝试使用 Scala 创建 Spring 数据 Mongo 存储库。 我的对象有 Int id,所以我的存储库看起来像

trait SamRecordRepo extends PagingAndSortingRepository[SamRecord, Int] {
}

这段代码无法编译,因为 scala Int 没有扩展 Serializable:

Error:(10, 29) type arguments [com.cgen.SamRecord2,Int] do not conform to trait PagingAndSortingRepository's type parameter bounds [T,ID <: java.io.Serializable]
trait SamRecordRepo extends PagingAndSortingRepository[SamRecord2, Int] {

我该如何解决这个问题?

也许改用 Integerjava.lang.Integer extends Serializable.