Spring Data Neo4j和Grails 3

4
有没有人使用Spring Data Neo4j(3.3.0)与Grails v3一起工作,并愿意共享配置?我想让Web界面正常工作(如此处所示:How to enable neo4j webadmin when using spring-data-neo4j?),但当尝试确定应该在Application.groovy中放入什么时,我有点迷失了,因为Grails从GrailsAutoConfiguration继承它,并且示例所示从Neo4jConfiguration继承它。

我在使用Grails 3.0运行Neo4j示例应用程序时遇到了一些问题。我在Github上开了一个问题,但是并没有看到太多关于这个问题的讨论。我很想看到一个可行的配置。 - Nathan
1
@Nathan,Stefan创建的Neo4J Grails插件非常糟糕,并且我甚至无法在2.4.3上使其正常工作。但是,我现在已经使用Grails 3成功使用了Spring Data Neo4J(http://projects.spring.io/spring-data-neo4j/),详细信息如下。 - John
1个回答

1
将以下依赖项添加到build.gradle中:
compile("org.springframework.data:spring-data-neo4j")
compile "org.neo4j.app:neo4j-server:2.1.5"
compile "org.neo4j.app:neo4j-server:2.1.5:static-web"

以下资源文件放在conf/spring中。

resources.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">

    <context:spring-configured/>
    <context:annotation-config/>

    <util:map id="config">
        <entry key="remote_shell_enabled" value="true"/>
    </util:map>

    <neo4j:config storeDirectory="target/data/db" base-package="com.example"/>

    <neo4j:repositories base-package="com.example.repositories"/>

    <bean id="graphDbFactory" class="org.neo4j.graphdb.factory.GraphDatabaseFactory"/>

    <bean id="graphDbBuilder" factory-bean="graphDbFactory" factory-method="newEmbeddedDatabaseBuilder">
        <constructor-arg value="target/data/db"/>
    </bean>

    <bean id="graphDbBuilderFinal" factory-bean="graphDbBuilder" factory-method="setConfig">
        <constructor-arg ref="config"/>
    </bean>

    <bean id="graphDatabaseService" factory-bean="graphDbBuilderFinal" factory-method="newGraphDatabase"
    destroy-method="shutdown"/>

    <bean id="serverWrapper" class="org.neo4j.server.WrappingNeoServerBootstrapper" init-method="start"
        destroy-method="stop">
        <constructor-arg ref="graphDatabaseService"/>
    </bean>
</beans>

resources.groovy(我相信这个文件可以从resources.xml中添加很多内容,但是我不确定该怎么做):

import com.example.MyGraph;

// Place your Spring DSL code here
beans = {
    myGraph(MyGraph)

}

src/main/groovy/com/example/MyGraph.java:

package com.example;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.data.neo4j.core.GraphDatabase;

@Configuration
public class MyGraph extends Neo4jConfiguration {

    @Autowired
    GraphDatabase graphDatabase;

}

我将Neo4J的领域类放在src/main/groovy/com/example/domain中,将存储库类放在src/main/groovy/com/example/repositories中。然后Spring示例代码就能正常工作了。当你运行grails run-app时,会在端口7474上提供Neo4J的Web服务器管理界面。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接