How to register custom Querydsl EntityPathResolver with Spring Data MongoRepositoryFactory?

泄露秘密 提交于 2019-12-13 00:47:36

问题


I am using the Querydsl extension (QueryDslPredicateExecutor) to my CrudRepository.

To reliably exclude the generated Q classes from my test coverage measurements, they are generated into a dedicated querydsl subpackage of the respective domain classes (annotation processor option -Aquerydsl.packageSuffix=.querydsl).

Alas, this causes a ClassNotFoundException at application start up:

java.lang.IllegalArgumentException: Did not find a query class org.example.QDomain for domain class org.example.Domain!
        at org.springframework.data.querydsl.SimpleEntityPathResolver.createPath(SimpleEntityPathResolver.java:63)
        at org.springframework.data.mongodb.repository.support.QueryDslMongoRepository.<init>(QueryDslMongoRepository.java:85)
        at org.springframework.data.mongodb.repository.support.QueryDslMongoRepository.<init>(QueryDslMongoRepository.java:67)
    …
Caused by: java.lang.ClassNotFoundException: org.example.QDomain
    …

I have already located the EntityPathResolver interface that supposedly would allow me to plug in my own domain class to Q class mapping that inserts the .querydsl package suffix, but I haven’t found a way to configure Spring Data’s MongoRepositoryFactory to pick my own EntityPathResolver.

Is this possible?


回答1:


Currently, the only way is to create your own variant of the MongoRepositoryFactory because the instance of the EntityPathResolver is hard-wired into it.



来源:https://stackoverflow.com/questions/47771175/how-to-register-custom-querydsl-entitypathresolver-with-spring-data-mongoreposit

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