将存储库impl放在非基础包中

时间:2011-09-04 17:03:35

标签: java spring spring-data

我不想将自定义存储库实现与域包分开。而且,可能是一些常见的接口。例如,我想要像

这样的结构
  com
       domain
            Foo
            FooRepository
       common
            Bar
       persistence
            BarImpl

interface FooRepository extends Bar{}

<jpa:repositories base-package="com.domain" /> // smt else?

我应该如何配置?

1 个答案:

答案 0 :(得分:3)

仅当您将存储库类放在同一个包中并使用默认的后缀或定义后缀以手动使用时,才能自动拾取存储库类。因此,在您的方案中,您必须将FooRepositoryImpl放入domain包中。您可以使用repository-impl-postfix属性自定义后缀。如果您想将实现放入另一个包中,可以使用fooRepositoryImpl作为bean id手动声明自定义实现bean。然后,该类可以驻留在您想要的任何包中。

我假设Bar是包含自定义方法声明的接口。实际上,我们建议将自定义存储库接口和实现放在同一个包中,并使其受到保护,以避免单独使用它。这样,所有客户端实际看到的是包含查询方法和手动实现的统一存储库接口。