Spring-Data-Envers存储库无法注入

时间:2015-08-28 09:09:27

标签: spring-data

在我的春天,我有以下几点:

<jpa:repositories base-package="x.y.service.springDataJpa"/>  
<jpa:repositories base-package="x.y.service.springDataEnvers"
                  factory-class="org.springframework.data.envers.repository.support.EnversRevisionRepositoryFactoryBean" />

这应该是我正常的spring-data-jpa存储库和我的spring-data-envers存储库。

但是在执行这个junit测试类时:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {ApplicationTestContext.class, OrmContext.class, DatasourceContext.class})
@ActiveProfiles(profiles = "LOCAL")
@Transactional
public class StoreAndRetrieveRevisionTest {

    @Inject
    private ServiceRepository serviceRepository;

    @Inject
    private ServiceRevisionRepository serviceRevisionRepository;

(ApplicationTestContext.class加载xml配置)。

无法注入revisionrepository bean:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'x.y.server.springDataJpa.hibernateenvers.StoreAndRetrieveRevisionTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private x.y.service.springDataEnvers.ServiceRevisionRepository x.y.server.springDataJpa.hibernateenvers.StoreAndRetrieveRevisionTest.serviceRevisionRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [x.y.service.springDataEnvers.ServiceRevisionRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@javax.inject.Inject()}

我在这里缺少什么? spring-data-envers文档相当稀疏。

1 个答案:

答案 0 :(得分:0)

请检查您的实体类是否已使用@Entity和@Table注释正确注释。如果不是,您的存储库bean将无法正确初始化,您将无法使用它。