Java SpringDataREST发布的自定义jpa存储库方法

Java SpringDataREST发布的自定义jpa存储库方法,java,spring,spring-data,spring-data-jpa,spring-data-rest,Java,Spring,Spring Data,Spring Data Jpa,Spring Data Rest,我已经向jpa存储库添加了一个自定义方法,如中所述 就我所见,当我使用SpringDataREST时,这个方法并没有公开。是否有任何方法可以将其发布为spring data REST生成的REST API的一部分(无需自己创建spring MVC控制器)?我检查了代码库-似乎他们明确禁用了自定义方法-不确定原因。以下是org.springframework.data.repository.core.support.DefaultRepositoryInformation中的相关代码 @Overr

我已经向jpa存储库添加了一个自定义方法,如中所述


就我所见,当我使用SpringDataREST时,这个方法并没有公开。是否有任何方法可以将其发布为spring data REST生成的REST API的一部分(无需自己创建spring MVC控制器)?

我检查了代码库-似乎他们明确禁用了自定义方法-不确定原因。以下是org.springframework.data.repository.core.support.DefaultRepositoryInformation中的相关代码

@Override
public Set<Method> getQueryMethods() {

    Set<Method> result = new HashSet<Method>();

    for (Method method : getRepositoryInterface().getMethods()) {
        method = ClassUtils.getMostSpecificMethod(method, getRepositoryInterface());
        if (isQueryMethodCandidate(method)) {
            result.add(method);
        }
    }

    return Collections.unmodifiableSet(result);
}

/**
 * Checks whether the given method is a query method candidate.
 * 
 * @param method
 * @return
 */
private boolean isQueryMethodCandidate(Method method) {
    return isQueryAnnotationPresentOn(method) || !isCustomMethod(method) && !isBaseClassMethod(method);
}
@覆盖
公共集getQueryMethods(){
Set result=new HashSet();
对于(方法:getRepositoryInterface().getMethods()){
method=ClassUtils.getMostSpecificMethod(方法,getRepositoryInterface());
if(isQueryMethodCandidate(方法)){
结果:添加(方法);
}
}
返回集合。不可修改集合(结果);
}
/**
*检查给定的方法是否为候选查询方法。
* 
*@param方法
*@返回
*/
私有布尔值isQueryMethodCandidate(方法){
返回isQueryNotationPresenton(方法)| |!isCustomMethod(方法)&&!isBaseClassMethod(方法);
}

我也面临同样的问题。任何帮助都将不胜感激。我想知道是否有人可以通过monkey patch绕过此检查,从而接受自定义方法?我很想听听SDR作者的意见,了解这是为什么。或者提及jira问题以允许这种行为。Oliver Gierke在这里解释了原因: