Spring Data Neo4j和Grails 3

时间:2015-06-22 15:03:43

标签: grails neo4j spring-data-neo4j

是否有人使用Spring Data Neo4j(3.3.0)与Grails v3合作并愿意分享配置?

我想让网络界面正常工作(按照此处:How to enable neo4j webadmin when using spring-data-neo4j?),但在尝试找出Application.groovy中的内容时,我有点迷失,就像Grails一样从GrailsAutoConfiguration扩展它,显示的示例将其从Neo4jConfiguration扩展。

1 个答案:

答案 0 :(得分: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;

}

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