@Repository
trait PersonRepository extends JpaRepository[Person, Long] { }
error: trait Repository is abstract; cannot be instantiated
[ERROR] @Repository
这个小特性由于明显的原因无法编译。但是我怎样可以在Scala中定义Spring Data JPA存储库?(Scala 2.10.3)
使用scala-test的示例测试用例:
@RunWith(classOf[JUnitRunner])
@ContextConfiguration(locations = Array("classpath:/moduleContext.xml"), loader = classOf[AnnotationConfigContextLoader])
class PersonRepositoryTest extends FunSpec with Matchers {
@Autowired var personRepository: PersonRepository = _
describe("Person repository") {
it("should persist a person") {
val person = new Person()
val persistedPerson = personRepository.save(person)
assert(persistedPerson.id >= 0)
}
}
}
interface
而不是trait
时它能工作吗? - Oliver Drotbohm