我正在爲variables
表編寫存儲庫,並希望使用它訪問特定的行。對於這個我想自動裝配主倉庫到定製的實現,像這樣:如何在Spring Data JPA中從cusom存儲庫訪問主存儲庫?
public interface VariableRepo extends CrudRepository<Variable, Long>, VariableRepoCustom {
Variable getByName(String name);
}
public interface VariableRepoCustom {
...
Variable getPopulationSingle();
...
}
public class VariableRepoCustomImpl implements VariableRepoCustom {
private final VariableRepo variableRepo;
@Autowired
public VariableRepoCustomImpl(VariableRepo variableRepo) {
this.variableRepo = variableRepo;
}
@Override
public Variable getPopulationSingle() {
return getByName("Population single");
}
...
}
不幸的是,春天喜歡去瘋狂與此,拋出一個異常:
錯誤與名製作豆「variableRepo ':調用init 方法失敗;嵌套異常是 org.springframework.data.mapping.PropertyReferenceException:否 property getPopulationSingle for type Variable!
I.e.它試圖在實體類(Variable
)內找到當然不應該包含在裏面的存儲庫方法。
如何解決這個問題?
您需要爲您的自定義回購命名爲impl'VariableRepoImpl' – mp911de