【问题标题】:querydsl default customize method cannot loadquerydsl 默认自定义方法无法加载
【发布时间】:2017-07-26 02:34:40
【问题描述】:

我在自定义方法中添加了一些绑定,参考下面的代码快照。现在有一个奇怪的问题,重启程序时,有时会加载customize方法,所以可以成功调用该方法,但有时却加载不出来,导致查询结果错误。我调试了资源注入 AdminRepository。卸载自定义方法时,spring的JdkDynamicTarget类没有缓存方法:

public interface AdminRepository extends CrudRepository<MonthGprs, String>,
    QueryDslPredicateExecutor<MonthGprs>, QuerydslBinderCustomizer<QMonthGprs> {
Logger log = LoggerFactory.getLogger (AdminRepository.class);
@Override
default public void customize(QuerydslBindings bindings, QMonthGprs root) {

    log.debug ("AdminRepository");

    bindings.bind (root.appLeftGprs).all (((path, value) -> {
        Iterator it = value.iterator ( );
        return path.goe ((Float) it.next ( )).and (path.loe ((Float) it.next ( )));
    }));

    bindings.bind (root.wifiLeftGprs).all (((path, value) -> {
        Iterator it = value.iterator ( );
        return path.between ((Float) it.next ( ), (Float) it.next ( ));
    }));

    bindings.bind (root.simInfo.createdDate).all (((path, value) -> {
        Iterator it = value.iterator ( );
        return path.after ((ZonedDateTime) it.next ( )).and (path.before ((ZonedDateTime) it
                .next ( )));
    }));

    bindings.bind (String.class)
            .first ((StringPath path, String value) -> path.containsIgnoreCase (value));
}

} 顺便说一句,我使用 com.querydsl:querydsl-mongodb:jar:4.1.4, org.springframework.boot:spring-boot-devtools:jar:1.4.1.RELEASE, org.springframework:spring-context-support:jar:4.3.3.RELEASE.

【问题讨论】:

    标签: spring mongodb querydsl


    【解决方案1】:

    我找到了为一个域模型定义两个存储库的原因,但是在

    org.springframework.data.repository.support.Repositories
    

    private final Map&lt;Class&lt;?&gt;, String&gt; repositoryBeanNames;

    此映射维护一个键值对,其中使用类作为键,存储库名称作为值。如果应用程序上下文有多个相同领域模型的存储库,则只加载一个存储库类。所以如果加载了query dsl repository,就调用customize方法,或者加载其他repository。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-28
      • 1970-01-01
      • 2013-03-06
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-14
      相关资源
      最近更新 更多