我正在为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