Creating a read-only repository with SpringData

后端 未结 6 450
后悔当初
后悔当初 2020-12-13 18:12

Is it possible to create read-only repositories using Spring Data?

I have some entities linked to views and some child entities for which I would like to provide a r

6条回答
  •  臣服心动
    2020-12-13 18:59

    To expand on Oliver Gierke's answer, in the more recent versions of Spring Data you will need the @NoRepositoryBean annotation on your ReadOnlyRepository (parent interface) to prevent application start up errors:

    import org.springframework.data.repository.NoRepositoryBean;
    import org.springframework.data.repository.Repository;
    
    @NoRepositoryBean
    public interface ReadOnlyRepository extends Repository {
    
        T findOne(ID id);
    
        List findAll();
    
    }
    

提交回复
热议问题