简体   繁体   English

Spring Data Neo4j存储库组合错误:找不到类型为YYYY的属性XXXX

[英]Spring Data Neo4j Repository Composition error: No property XXXX found for type YYYY

This should be a simple question about something that I'm probably missing from the Spring Data documentation. 这应该是一个关于我可能从Spring Data文档中遗漏的一些简单问题。

I'm trying to implement a repository extension as described in: http://docs.spring.io/spring-data/data-neo4j/docs/3.0.2.RELEASE/reference/html/programming-model.html#d0e2970 . 我正在尝试实现一个存储库扩展,如下所述: http//docs.spring.io/spring-data/data-neo4j/docs/3.0.2.RELEASE/reference/html/programming-model.html#d0e2970

The code is really simple. 代码非常简单。 I just have a repository and an extension interface (and implementation). 我只有一个存储库和一个扩展接口(和实现)。

First a repository for MyType class: 首先是MyType类的存储库:

public interface MyTypeRepository extends 
        GraphRepository<MyType>, MyTypeRepositoryExtension { }

Then the extension interface: 然后是扩展界面:

public interface MyTypeRepositoryExtension {
    void anyMethodNameForQuery();
}

And its implementation: 它的实施:

public class MyTypeRepositoryExtensionImpl {

     public void anyMethodNameForQuery() {
          //custom query code
     }
 }

With this code, Spring Data throws an error while bootstrapping its mapping infrastructure: 使用此代码,Spring Data会在引导其映射基础结构时抛出错误:

Caused by: org.springframework.data.mapping.PropertyReferenceException: No property any found for type MyType!

As what I'm understanding from this error, any method that is added to the extension interface Spring Data tries to map to a property of the respective type. 正如我从这个错误中理解的那样,任何添加到扩展接口的方法Spring Data都会尝试映射到相应类型的属性。 But that is the only use of repository extensions? 但这是存储库扩展的唯一用途? That is not what I was understanding from the documentation (linked above). 这不是我从文档中理解的(上面链接的)。 If that is true what are the alternatives for custom queries? 如果这是真的,那么自定义查询的替代方案是什么?

A final observation is that I'm aware of @Query annotation, but my use case require a specific traversal and dynamic query composition. 最后一个观察是我知道@Query注释,但我的用例需要特定的遍历和动态查询组合。


EDIT: FURTHER INFORMATION 编辑:更多信息

Looking at the documentation again I found some information that might be related to this. 再次查看文档,我发现了一些可能与此相关的信息。 In order to configure repository composition it is necessary to change repository scan path from org.example.repository to org.springframework.data.neo4j . 为了配置存储库组合,有必要将存储库扫描路径从org.example.repository更改为org.springframework.data.neo4j That is why any method that I put in the MyTypeRepositoryExtension interface Spring Data was trying to map to a MyType property. 这就是为什么我放在MyTypeRepositoryExtension接口Spring Data中的任何方法都试图映射到MyType属性。

I've set Spring Data Neo4j repository scan path as documented, but I've got many runtime class not found errors such as: java.io.FileNotFoundException: class path resource [javax/enterprise/inject/spi/Extension.class] cannot be opened because it does not exist" . 我已经设置了Spring Data Neo4j存储库扫描路径,但是我有很多运行时类没有找到错误,例如: java.io.FileNotFoundException: class path resource [javax/enterprise/inject/spi/Extension.class] cannot be opened because it does not exist"

In a try-and-error-totally-adhoc manner I have managed to find some dependencies that could fill out the missing classes. 我试图找到一些可以填补缺少的类的依赖项,这是一种尝试错误的完全特殊的方式。 I've ended up with these dependencies: 我最终得到了这些依赖项:

    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-core</artifactId>
        <version>3.3.3</version>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-lucene4</artifactId>
        <version>3.3.3</version>
        <optional>true</optional>
        <exclusions>
            <exclusion>
                <groupId>org.apache.lucene</groupId>
                <artifactId>lucene-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
        <version>3.3.3</version>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>1.0-SP1</version>
    </dependency>

That eliminated the class not found errors, but now, since I changed the repository path, Spring is not able to inject the repositories. 这消除了类未找到错误,但现在,由于我更改了存储库路径,Spring无法注入存储库。

The documentation tries to say something about this I think, but I couldn't understand what "put it behind" means in the phrase (from the documentation): "If you use <context:component-scan> in your spring config, please make sure to put it behind <neo4j:repositories> , as the RepositoryFactoryBean adds new bean definitions for all the declared repositories, the context scan doesn't pick them up otherwise" . 文档尝试说出我想的一些事情,但是我无法理解短语(来自文档)中的置之不理”意思: “如果你在spring配置中使用<context:component-scan> ,请确保把它放在<neo4j:repositories>后面,因为RepositoryFactoryBean为所有声明的存储库添加了新的bean定义,否则上下文扫描不会选择它们“

To sum up I really need some orientation here :-) ... Also, I think that the documentation needs to define the needed dependencies. 总结一下,我真的需要一些方向:-) ...另外,我认为文档需要定义所需的依赖项。 And describe how extension repositories and standard repositories (interface only) can be mixed in a project. 并描述如何在项目中混合扩展存储库和标准存储库(仅限接口)。

I know after one year probably the answer won't be useful for you, but maybe can help other people who is struggling with spring-data-neo4j , like myself these days (see question ) 我知道一年之后可能答案对你spring-data-neo4j ,但也许可以帮助其他正在与spring-data-neo4j ,就像我这些天一样(见问题

Just point two things you need to change: 只需指出需要改变的两件事:

1) Following the spring-data repository naming conventions, the name of the implementation of your custom repository has to be EntityRepsitoryImpl (although the default sufix Impl can be changed by configuration). 1)遵循spring-data存储库命名约定,自定义存储库的实现名称必须是EntityRepsitoryImpl (尽管可以通过配置更改默认的sufix Impl)。 So, you need to change MyTypeRepositoryExtensionImpl for MyTypeRepositoryImpl 所以,你需要改变MyTypeRepositoryExtensionImplMyTypeRepositoryImpl

2) You don't need to change the neo4j:repositories package. 2)您无需更改neo4j:repositories包。 org.example.repository is fine. org.example.repository很好。 Don't use org.springframework.data.neo4j 不要使用org.springframework.data.neo4j

3) Concerning the dependencies needed, if you don't change the package repository as mentioned in the point 2, is enough with the basics: 3)关于所需的依赖关系,如果您没有按照第2点中的说明更改软件包存储库,那么基础知识就足够了:

  • org.springframework.data.spring-data-neo4j org.springframework.data.spring-数据的Neo4j
  • javax.validation.validation-api javax.validation.validation-API
  • com.sun.jersey.jersey-client com.sun.jersey.jersey客户端

I agree with you that spring-data-neo4j repository composition is a bit confusing and there are very few good examples online... So, finally I've decided to create a sample project on GitHub, with a basic example showing how we can do that. 我同意你的观点, spring-data-neo4j存储库组合有点令人困惑,在网上很少有很好的例子......所以,最后我决定在GitHub上创建一个示例项目,其基本示例展示了我们如何能够去做。

Hope it help other people in the future. 希望它能在未来帮助其他人。

See on GitHub : neo4jCustomRepository 请参阅GitHubneo4jCustomRepository

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Data Neo4j“找不到类型的属性”异常 - Spring Data Neo4j “No property get found for type” exception DataRetrievalFailureException:在Spring Data Neo4j中找不到&#39;__type__&#39; - DataRetrievalFailureException: '__type__' Not Found in Spring Data Neo4j “没有找到类型的属性”组合存储库spring-data-neo4j - “No property found for type” combining repositories spring-data-neo4j Spring Neo4j:NoSuchBeanDefinitionException:找不到依赖项类型为[org.springframework.data.neo4j.support.Neo4jTemplate]的合格bean - Spring Neo4j: NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.data.neo4j.support.Neo4jTemplate] found for dependency 使用Spring数据Neo4j 4的部分实现的存储库 - Partially implemented repository with Spring data Neo4j 4 Neo4j 嵌套关系加载使用 spring 数据存储库 - Neo4j nested relations loading using spring data repository Spring-Data Neo4J @Repository @Query不起作用 - Spring-Data Neo4J @Repository @Query not working 关系实体的 Spring Data Neo4j 存储库 - Spring Data Neo4j Repository for Relationship Entity Spring Data Neo4J存储库findAll()导致nullpointerexception - Spring Data Neo4J repository findAll() results in a nullpointerexception Spring Data Neo4j存储库初始化方法调用失败 - Spring Data Neo4j repository Invocation of init method failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM