代码之家  ›  专栏  ›  技术社区  ›  Andreas Sewe

如何向Spring Data MongoRepositoryFactory注册自定义Querydsl EntityPathResolver?

  •  1
  • Andreas Sewe  · 技术社区  · 8 年前

    我正在使用 Querydsl extension ( QueryDslPredicateExecutor )给我的 CrudRepository .

    可靠地排除生成的 Q 类从我的测试覆盖率度量中,生成一个专用 querydsl 各个域类的子包(注释处理器选项 -Aquerydsl.packageSuffix=.querydsl ).

    唉,这会导致 ClassNotFoundException 应用程序启动时:

    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
        …
    

    我已经找到了 EntityPathResolver interface 应该可以让我自己插上电源 域类 Q 插入 .querydsl 包后缀,但我还没有找到配置Spring数据的方法 MongoRepositoryFactory 选择我自己的 EntityPathResolver .

    这可能吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Jens Schauder    8 年前

    目前,唯一的方法是创建您自己的 MongoRepositoryFactory 因为 EntityPathResolver 与之紧密相连。