Is it possible to use spring-data-rest-webmvc without an actual Repository?

我只是一个虾纸丫 提交于 2019-12-04 02:15:34

问题


The question may sound funny but I think this should be possible.

What I want is to use a repository that is purely custom but is exposed just like a Repository. This service would have methods to get, save, delete and list objects where the data could be from any arbitrary source.

Looking through the code, I think it should be possible since methods are accessed using CrudMethods and RepositoryInvoker. I belief this requires an implementation of RepositoryFactoryInformation that will be discovered by Repositories. I started experimenting a bit and it looks like a full-blown spring-data-noop module.

Am I on the right track or is there an easier way to accomplish this?


回答1:


I've ended up writing spring-data-custom to create fully customized spring-data repositories, allowing custom code to be used with spring-data-rest etc.

  1. Enable custom repositories (@EnableCustomRepositories)
  2. Annotate eligible entities (@Custom)
  3. Create a repository (extend CustomRepository<T, ID>)
  4. Add custom behavior:
    1. Let repository extend a new interface with the Custom suffix
    2. Create an implementation of the new interface with the Impl prefix
    3. Add one or more CRUD methods named findOne, save, findAll, delete (see DefaultCrudMethods)
    4. Add query methods annotated with @Query
  5. Export repository using spring-data-rest

(copied from README)

As @wwadge correctly mentioned, spring-data-keyvalue is an alternative. Repositories have to implement KeyValueAdapter, e.g. MapKeyValueAdapter.




回答2:


The easier way is to use spring-data-keyvalue project which does what you are trying to do.



来源:https://stackoverflow.com/questions/35554297/is-it-possible-to-use-spring-data-rest-webmvc-without-an-actual-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!