"No property found for type" 合并存储库 spring-data-neo4j

"No property found for type" combining repositories spring-data-neo4j

我正在使用 spring-data-neo4j 并且我正在尝试合并存储库以便能够使用自定义存储库。我想我已经正确地遵循了 20.8.7 Creating repositories and other SO questions like this 中指定的命名约定。

无论如何,我做错了什么,因为我得到了这个

异常信息

Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property someCriteria found for type User!

用户实体

@NodeEntity
public class User {

   @GraphId
   private Long nodeId;
   @Indexed
   String mail;
   ...
}

存储库(全部在同一个包中)

@Repository
public interface UserRepository extends GraphRepository<User>, UserRepositoryCustom {
   User findByMail(String mail);
}

public interface UserRepositoryCustom {
  String findBySomeCriteria(String criteria);
}

public class UserRespositoryImpl implements UserRepositoryCustom {
   @Override
   public String findBySomeCriteria(String criteria) {
      return "result";
   }
}

服务

@Service
public class UserServiceImpl implements UserService {
   @Autowired
   UserRepository userRepository;
}

Neo4j 配置

<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
      ...
</bean>
<neo4j:repositories base-package="com.mypackage.api.user.repository"/>
<bean id="userService" class="com.mypackage.api.user.service.UserServiceImpl"/>

在这种情况下,这只是一个愚蠢的 spelling 错误。

需要根据 UserRepositoryImpl 更改 UserRespositoryImpl(没有“s”:注意 UserRespositoryImpl)。

无论如何,我一直在努力处理 spring-data-neo4j 中的自定义存储库组合,我认为它可能有点令人困惑。此外,我认为网上很少有好的示例...因此,最后我决定在 GitHub 上创建一个示例项目,并通过一个基本示例展示我们如何做到这一点。

希望以后对其他人有所帮助。

参见 GitHub:neo4jCustomRepository