Andres Andres - 1 year ago 108
Java Question

Custom jpa repository method published by spring-data-rest

I've added a custom method to a jpa repository as detailed on

As far as I could see, this method is not exposed when I use spring-data-rest. Is there any way I could publish it as part of the REST API generated by spring-data-rest (without creating a Spring MVC Controller myself)?

Answer Source

I checked the code base - seems like they have explicitily disabled custom methods - not sure why. Here is the relevant piece of code from

public Set<Method> getQueryMethods() {

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

    for (Method method : getRepositoryInterface().getMethods()) {
        method = ClassUtils.getMostSpecificMethod(method, getRepositoryInterface());
        if (isQueryMethodCandidate(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);