如何查看Spring Data MongoDB生成的存储库实现? [英] How to see the repository implementation generated by Spring Data MongoDB?

查看:91
本文介绍了如何查看Spring Data MongoDB生成的存储库实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Spring Data何时生成存储库的实现?在编译时还是在运行时?我可以看到Spring Data生成的实现存储库实现吗?

When is the implementation for repositories generated by Spring Data? At compile time or runtime? Can I see the implementation repository implementation generated by Spring Data?

推荐答案

tl; dr

不,原因很简单:没有代码生成正在进行.该实现基于代理和方法拦截器,将调用执行委派到正确的位置.

tl;dr

No, for a very simple reason: there's no code generation going on. The implementation is based on proxies and a method interceptor delegating the call executions to the right places.

有效地,方法执行可以由3种类型的代码支持:

Effectively, a method execution can be backed by 3 types of code:

  1. CrudRepository的商店特定实现.看一下名为Simple(Jpa|Mongo|Neo4|…)Repository的类型(请参阅JPA特定的一种

  1. The store specific implementation of CrudRepository. Have a look for types named Simple(Jpa|Mongo|Neo4|…)Repository (see the JPA specific one here). They have "real" implementations for all of the methods in CrudRepository and PagingAndSortingRepository.

查询方法由QueryExecutorMethodInterceptor.doInvoke(…)有效执行(请参见

Query methods are effectively executed by QueryExecutorMethodInterceptor.doInvoke(…) (see here). It's basically a 3-step-process to find the delegation target and invoke it. The actual execution is done in classes named (Jpa|Mongo|Neo4j…)QueryExecution (see this one for example).

剩下的唯一一件事就是查询派生,它由两个主要部分组成:方法名称解析和查询创建.对于前者,请查看PartTree.它带有一个方法名称和一个基本类型,并且将返回一个已解析的类似AST的结构,如果无法解析属性等,则将引发异常.

The only thing left is the query derivation, which consists of two major parts: method name parsing and query creation. For the former, have a look at PartTree. It takes a method name and a base type and will return you a parsed AST-like structure or throw an exception if it fails to resolve properties or the like.

后者在名为PartTree(Jpa|Mongo|Neo4j|…)Query的类中实现,并委托给其他组件以实际创建商店特定的查询.例如.对于JPA,有趣的地方可能在JpaQueryCreator.PredicateBuilder.build()中(请参阅

The latter is implemented in classes named PartTree(Jpa|Mongo|Neo4j|…)Query and delegates to additional components for actually creating the store specific query. E.g. for JPA the interesting bits are probably in JpaQueryCreator.PredicateBuilder.build() (see here).

这篇关于如何查看Spring Data MongoDB生成的存储库实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆