2014-01-14 59 views

回答

11

我檢查了代碼庫 - 好像他們有可明確禁用自定義的方法 - 不知道爲什麼。這裏是來自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); 
} 
+1

我不知道是否可以用猴子補丁繞過這個檢查,以便它接受自定義方法? – wakandan

+2

我很想聽聽特別提款權作者爲什麼會這樣做。或者提一個jira問題來允許這種行爲。 – Jay

+2

奧利弗·基爾克解釋爲什麼在這裏:http://stackoverflow.com/questions/25201306/implementing-custom-methods-of-spring-data-repository-and-exposing-them-through –