Spring Data Neo4j Repository Composition错误:找不到类型为YYYY的属性XXXX [英] Spring Data Neo4j Repository Composition error: No property XXXX found for type YYYY

查看:101
本文介绍了Spring Data Neo4j Repository Composition错误:找不到类型为YYYY的属性XXXX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该是一个关于Spring Data文档中可能缺少的问题的简单问题.

This should be a simple question about something that I'm probably missing from the Spring Data documentation.

我正在尝试实现存储库扩展,如以下所述:

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.

代码非常简单.我只有一个存储库和一个扩展接口(和实现).

The code is really simple. I just have a repository and an extension interface (and implementation).

首先是MyType类的存储库:

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

然后扩展界面:

public interface MyTypeRepositoryExtension {
    void anyMethodNameForQuery();
}

及其实现:

public class MyTypeRepositoryExtensionImpl {

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

使用此代码,Spring Data在引导其映射基础结构时引发错误:

With this code, Spring Data throws an error while bootstrapping its mapping infrastructure:

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

据我从此错误中了解,添加到扩展接口Spring Data中的任何方法都试图映射到相应类型的属性.但这是存储库扩展的唯一用途吗?那不是我从文档(上面链接的)中了解的内容.如果是这样,那么自定义查询的替代方法是什么?

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. 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?

最后的观察结果是,我知道了@Query批注,但是我的用例需要特定的遍历和动态查询组合.

A final observation is that I'm aware of @Query annotation, but my use case require a specific traversal and dynamic query composition.

更多信息

再次查看文档,我发现了一些可能与此相关的信息.为了配置存储库组成,必须将存储库扫描路径从org.example.repository更改为org.springframework.data.neo4j.这就是为什么我在Spring Data的MyTypeRepositoryExtension接口中放置的任何方法都试图映射到MyType属性的原因.

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. That is why any method that I put in the MyTypeRepositoryExtension interface Spring Data was trying to map to a MyType property.

我已将Spring Data Neo4j存储库扫描路径设置为已记录,但我发现许多运行时类未发现错误,例如:java.io.FileNotFoundException: class path resource [javax/enterprise/inject/spi/Extension.class] cannot be opened because it does not exist".

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".

我尝试了一些尝试性的错误,设法找到了一些可以填补缺失类的依赖项.我最终遇到了这些依赖关系:

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>

这消除了该类未发现错误,但是现在,由于我更改了存储库路径,因此Spring无法注入存储库.

That eliminated the class not found errors, but now, since I changed the repository path, Spring is not able to inject the repositories.

该文档试图说一些我认为的内容,但是我无法理解(在文档中)把它抛在后面"是什么意思:"如果您在spring config中使用<context:component-scan> ,请确保将其放在<neo4j:repositories>后面,因为RepositoryFactoryBean为所有已声明的存储库添加了新的bean定义,否则上下文扫描不会选择它们." .

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".

总而言之,我在这里确实需要一些指导:-) ...另外,我认为文档需要定义所需的依赖关系.并描述如何在项目中混合扩展存储库和标准存储库(仅用于接口).

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.

推荐答案

我知道一年后答案可能对您没有用,但也许可以帮助其他正在为spring-data-neo4j苦苦挣扎的人,例如我自己天(请参见问题 )

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)

只需指出您需要更改的两件事:

Just point two things you need to change:

1)遵循spring-data存储库命名约定,自定义存储库的实现名称必须为EntityRepsitoryImpl(尽管默认sufix Impl可以通过配置进行更改).因此,您需要将MyTypeRepositoryExtensionImpl更改为MyTypeRepositoryImpl

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). So, you need to change MyTypeRepositoryExtensionImpl for MyTypeRepositoryImpl

2)您不需要更改neo4j:repositories软件包. org.example.repository很好. 请勿使用org.springframework.data.neo4j

2) You don't need to change the neo4j:repositories package. org.example.repository is fine. Don't use org.springframework.data.neo4j

3)关于所需的依赖关系,如果您不按第2点所述更改软件包存储库,则基本知识就足够了:

3) Concerning the dependencies needed, if you don't change the package repository as mentioned in the point 2, is enough with the basics:

  • org.springframework.data.spring-data-neo4j
  • javax.validation.validation-api
  • com.sun.jersey.jersey-client
  • org.springframework.data.spring-data-neo4j
  • javax.validation.validation-api
  • com.sun.jersey.jersey-client

我同意您的观点,即spring-data-neo4j存储库的构成有点令人困惑,并且网上很少有很好的示例...因此,最后,我决定在GitHub上创建一个示例项目,其中一个基本示例显示了我们如何可以做到.

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.

希望它对以后的人有所帮助.

Hope it help other people in the future.

GitHub上查看: neo4jCustomRepository

这篇关于Spring Data Neo4j Repository Composition错误:找不到类型为YYYY的属性XXXX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆