当前位置: 首页 > 知识库问答 >
问题:

使用neo4j 2有效设置Spring-data-neo4f

董建德
2023-03-14

我有一个困难的时间设置我的项目使用sping-data-neo4j和新的neo4j版本2.0(因为我想在neo4j中使用新的标签)

经过一番努力,我找到了sping-data-neo4j 3.0.0。maven存储库中的RC1。此外,我想使用neo4j空间。相关的maven依赖关系定义如下:

        <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.0.0.RELEASE</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.0.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>3.0.0.RC1</version>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate.javax.persistence</groupId>
                <artifactId>hibernate-jpa-2.0-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-spatial</artifactId>
        <version>0.12-neo4j-2.0.0-M06</version>
    </dependency>

应用程序上下文如下项目网站上的示例所示:

<context:annotation-config/>
<context:spring-configured/>
<context:component-scan base-package="org.some.packages"/>

<neo4j:config storeDirectory="target/my.db"/>
<neo4j:repositories base-package="org.some.packages.repository"/>


<tx:annotation-driven mode="proxy"/>

我不使用ASHOJ。

当我启动项目时,我得到以下异常:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someRepository': Invocation of init method failed; nested exception is org.neo4j.graphdb.TransactionFailureException: Unable to commit transaction
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:681)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:121)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:250)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
Caused by: org.neo4j.graphdb.TransactionFailureException: Unable to commit transaction
at org.neo4j.kernel.TopLevelTransaction.close(TopLevelTransaction.java:134)
at org.springframework.data.neo4j.support.DelegatingGraphDatabase.createIndex(DelegatingGraphDatabase.java:175)
at org.springframework.data.neo4j.support.index.IndexProviderImpl.createIndex(IndexProviderImpl.java:91)
at org.springframework.data.neo4j.support.index.IndexProviderImpl.getIndex(IndexProviderImpl.java:68)
at org.springframework.data.neo4j.support.index.IndexProviderImpl.getIndex(IndexProviderImpl.java:108)

失败的´´´´´´´someRepository bean是一个扩展GraphRespository的简单接口。

该设置与最新的稳定版本if-spring-data-neo4j配合使用(在发动机罩下使用neo4j 1.9)

有什么想法吗?

编辑:我的一个@NodeEntity上有一个属性,它具有以下索引定义

    @Indexed(indexType = IndexType.POINT, indexName = "someIndexName", unique = false)

如果删除此索引,则可以启动应用程序上下文。

共有1个答案

程举
2023-03-14

通过在pom中添加一些其他依赖项,我能够解决这个问题。xml文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>it.larusba.spikes.neo4j</groupId>
<artifactId>neo4art</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>neo4art spike based on Neo4j, Heroku, GeoSpatial, MapQuest</description>
<packaging>war</packaging>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <source.level>1.7</source.level>
    <target.level>1.7</target.level>

    <spring.version>4.0.2.RELEASE</spring.version>
    <spring.ws.version>2.1.4.RELEASE</spring.ws.version>
    <castor.version>1.3.3</castor.version>

    <spring.data.neo4j.version>3.0.1.RELEASE</spring.data.neo4j.version>
    <neo4j.spatial.version>0.12-neo4j-2.0.1</neo4j.spatial.version>
    <neo4j.graphcollections.version>0.7.1-neo4j-2.0.1</neo4j.graphcollections.version>
</properties>

<dependencies>

    <!-- Spring -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aspects</artifactId>
        <version>${spring.version}</version>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <!-- Spring Data Neo4j -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>${spring.data.neo4j.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j-rest</artifactId>
        <version>${spring.data.neo4j.version}</version>
    </dependency>

    <!-- Neo4j Geo-Spatial -->
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-spatial</artifactId>
        <version>${neo4j.spatial.version}</version>
    </dependency>

    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-graph-collections</artifactId>
        <version>${neo4j.graphcollections.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.neo4j</groupId>
                <artifactId>neo4j</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.neo4j</groupId>
                <artifactId>neo4j-lucene-index</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.vividsolutions</groupId>
        <artifactId>jts</artifactId>
        <version>1.13</version>
    </dependency>

    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>

    <dependency>
        <groupId>org.opengis</groupId>
        <artifactId>geoapi</artifactId>
        <version>3.0.0</version>
    </dependency>

     <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-shapefile</artifactId>
        <version>9.2</version>
    </dependency>

    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-swing</artifactId>
        <version>9.2</version>
    </dependency>

    <!-- Necessaria con l'annotazione @Configuration -->
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>

    <!-- Jackson JSON Mapper -->
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.7.1</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jettison</groupId>
        <artifactId>jettison</artifactId>
        <version>1.3.5</version>
    </dependency>

    <!-- REST: Marshalling/Unmarshalling XML to OBJECT -->
    <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-oxm</artifactId>
       <version>${spring.version}</version>
    </dependency>
    <dependency>
       <groupId>org.springframework.ws</groupId>
       <artifactId>spring-ws-core</artifactId>
       <version>${spring.ws.version}</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.castor</groupId>
        <artifactId>castor-xml</artifactId>
        <version>${castor.version}</version>
    </dependency>

    <!-- @Inject -->
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>

    <!-- JSR 303 Validator -->
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.1.0.Final</version>
    </dependency>

    <!--  Apache Commons -->
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency>
    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.3</version>
    </dependency>
    <dependency>
        <groupId>commons-beanutils</groupId>
        <artifactId>commons-beanutils</artifactId>
        <version>1.8.0</version>
    </dependency>

    <!-- DTO -->
    <dependency>
        <groupId>net.sf.dozer</groupId>
        <artifactId>dozer</artifactId>
        <version>5.4.0</version>
    </dependency>

    <!-- Servlet -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <!-- Logging: slf4j -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>jcl-over-slf4j</artifactId>
        <version>1.5.8</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.5.8</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.8</version>
    </dependency>

    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>

    <!-- Test -->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
        <scope>test</scope>
    </dependency>

</dependencies>

<build>

    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>${source.level}</source>
                <target>${target.level}</target>
                <encoding>${project.build.sourceEncoding}</encoding>
            </configuration>
        </plugin>

    </plugins>

</build>

<repositories>

    <repository>
        <id>spring-maven-snapshot</id>
        <name>Springframework Maven MILESTONE Repository</name>
        <snapshots><enabled>true</enabled></snapshots>
        <url>http://maven.springframework.org/milestone</url>
    </repository>

    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <snapshots><enabled>true</enabled></snapshots>
        <url>http://repo.spring.io/snapshot</url>
    </repository>       

    <repository>
        <id>neo4j-repository</id>
        <snapshots><enabled>true</enabled></snapshots>
        <name>Neo4j RELEASES Repository</name>
        <url>http://m2.neo4j.org/content/repositories/releases</url>
    </repository>

    <repository>
        <id>osgeo</id>
        <name>Open Source Geospatial Foundation Repository</name>
        <url>http://download.osgeo.org/webdav/geotools/</url>
    </repository>

</repositories> 

<pluginRepositories>

    <pluginRepository>
        <id>spring-plugins-release</id>
        <url>http://libs.spring.io/plugins-release</url>
    </pluginRepository>

</pluginRepositories>

特别是请查看“Neo4j地理空间”部分:添加这两个地理工具依赖项后,我终于能够解决您的相同问题。

我正在使用SDN3.0。1和neo4j 2.0。1.

希望会有所帮助。

干杯,

洛伦佐

 类似资料:
  • 我需要从我的微服务提供到Redis的安全连接。 所以如果我想添加支持身份验证的能力,以便客户端可以发送带有密码的AUTH命令。参见http://redis.io/topics/security 如何使用Spring Data Redis实现来完成此操作?

  • 根据官方的elasticsearch的说法,我知道嵌套需要在添加/删除/更新操作时将父级与其子级重新绑定,因此当需要大量修改时代价很高。 使用嵌套的示例:

  • 问题内容: 通过Spring-Data-Elasticsearch,我试图使用在 elasticsearch_config.json中 定义的分析器和映射。 该JSON文件位于 / src / main / resources 文件夹中。 我的JAVA模型如下所示: elasticsearch_config.json 包含设置和映射: 我尝试了curl,索引/搜索没有问题。 我的问题 : 我想使用

  • 我正在尝试配置我的应用程序上下文,以便能够在我的应用程序中使用带有嵌入式图形的Neo4j服务器,但没有多大成功。我同时使用Spring数据(Mongo和Neo4j存储库方法)。这是我的应用程序上下文,未运行: 如果我不使用这种方法,只指定存储目录(注释行),那么一切都可以正常运行。我怀疑这是SDN和neo4j服务器之间的版本问题。这是我的POM: 它的父项作为依赖项Spring(核心、上下文、测试

  • vuetify3的v-data-table-virtual表格中的表头如何禁用排序? 以下是目前的代码 根据官方给出的文档,我把sortable设成false。但是实际上表头还是能排序,可能是哪里出了问题吗? 顺带一个问题,为什么文档里给出的说明都写着readonly?这个属性不应该是可以写的吗。以下官方文档的片段。 vuetify table的链接:https://vuetifyjs.com/z