SpringDataNeo4j没有在Grails中创建唯一的索引/约束

SpringDataNeo4j没有在Grails中创建唯一的索引/约束,grails,neo4j,spring-data-neo4j,Grails,Neo4j,Spring Data Neo4j,在grails中使用spring-data-neo4j时,我在获取唯一约束方面遇到了一些问题 我怀疑这是因为我没有正确连接它,但是存储库正在被扫描和连接,CRUD正在工作,所以我不确定我做错了什么 我使用的是grails 2.4.3,具有以下依赖项: neo4jVerison="2.1.5" dependencies { compile("org.neo4j:neo4j-community:$neo4jVerison") compile("org.neo4j.app:ne

在grails中使用spring-data-neo4j时,我在获取唯一约束方面遇到了一些问题

我怀疑这是因为我没有正确连接它,但是存储库正在被扫描和连接,CRUD正在工作,所以我不确定我做错了什么

我使用的是grails 2.4.3,具有以下依赖项:

  neo4jVerison="2.1.5"
  dependencies {
    compile("org.neo4j:neo4j-community:$neo4jVerison")
    compile("org.neo4j.app:neo4j-server:$neo4jVerison")
    compile("org.neo4j:neo4j-rest-graphdb:2.0.1")
    compile("org.neo4j:neo4j-spatial:0.13-neo4j-2.1.4")
    compile 'org.springframework.data:spring-data-neo4j:3.2.1.RELEASE'
    test group:"org.neo4j", name:"neo4j-kernel", version: "$neo4jVerison", classifier:"tests"
    test "org.grails:grails-datastore-test-support:1.0-grails-2.4"
    test "xmlunit:xmlunit:1.5"
} 
这些bean用于我的测试环境:

testGraphDatabaseFactory(org.neo4j.test.TestGraphDatabaseFactory)
graphDb(GraphDatabaseService) { bean ->
    bean.factoryBean = "testGraphDatabaseFactory"
    bean.factoryMethod = "newImpermanentDatabase"
    bean.destroyMethod = "shutdown"  }

xmlns neo4j:"http://www.springframework.org/schema/data/neo4j"
neo4j.'repositories'( 'base-package': "repositories" )
neo4jTemplate(Neo4jTemplate, graphDb)
neo4jMappingContext(Neo4jMappingContext)
tx(NeoTransactions, graphDb)
tx类只公开一个启动graphDb事务的“tx.tx{closure}”方法,即使关闭失败也会关闭它

我的域类是:

package repositories

import org.springframework.data.neo4j.annotation.GraphId
import org.springframework.data.neo4j.annotation.Indexed
import org.springframework.data.neo4j.annotation.NodeEntity

@NodeEntity
class Junction {
    @GraphId Long id;
    @Indexed(unique = true) Long legacyId
}
存储库是:

package repositories

import org.springframework.data.neo4j.repository.GraphRepository

interface JunctionRepository extends GraphRepository<Junction> {}
奇怪的是,虽然只保存了一个连接(即1==junctionRepository.count()),但在我尝试保存修改后的j3时没有引发异常

此外,当我在Neo4J web控制台中打开数据库并运行:schema时,它不会显示为创建了任何索引/约束

我猜我的连接没有正确配置,因为我认为应该在连接时解析域对象时设置索引

有人知道少了什么吗

后续行动1

我怀疑我不应该手动创建模板或映射上下文。标准弹簧配置似乎是

但是,当我尝试通过spring dsl执行此操作时,我遇到了一个奇怪的错误:

 xmlns neo4j:"http://www.springframework.org/schema/data/neo4j"
 neo4j.'repositories'( 'base-package': "repositories" )
 neo4j.'config'( 'graphDatabaseService': "graphDb" )
错误是:

| Error Fatal error running tests: Error creating bean with name 'junctionRepository':
  Cannot resolve reference to bean 'neo4jTemplate' while setting bean property 'neo4jTemplate';
  nested exception is org.springframework.beans.factory.BeanCreationException: Error creating
   bean with name 'neo4jTemplate' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration:
  Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.Neo4jTemplate org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTemplate() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jMappingContext' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.mapping.Neo4jMappingContext org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jMappingContext() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityIndexCreator' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.mapping.EntityIndexCreator org.springframework.data.neo4j.config.Neo4jConfiguration.entityIndexCreator() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexProvider' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.index.IndexProvider org.springframework.data.neo4j.config.Neo4jConfiguration.indexProvider() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'graphDatabaseService' is defined (Use --stacktrace to see the full trace)
嗯:没有定义名为“graphDatabaseService”的bean?那是虫子吗neo4j.config'('graphDatabaseService':“graphDb”)告诉它使用graphDbbean,不是吗

后续行动2


如果我将bean名称更改为graphDatabaseService,它可以正常工作。看起来neo4j.config没有将命名的graphDb bean传递给它构造的所有对象。:)

是的,它确实依赖于名称
graphDatabaseService
(不幸的是)


还要确保你的tx类也调用了
tx.success()
而不仅仅是
tx.close()

,这在文档中并不清楚-花费了我几天的时间在黑暗中摸索:([只有当我来写它的时候,我才真正解决了这个问题……令人惊讶的是,向别人解释它能巩固我的想法].是的,我的tx.tx确实调用success and close:)。Tnx。
| Error Fatal error running tests: Error creating bean with name 'junctionRepository':
  Cannot resolve reference to bean 'neo4jTemplate' while setting bean property 'neo4jTemplate';
  nested exception is org.springframework.beans.factory.BeanCreationException: Error creating
   bean with name 'neo4jTemplate' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration:
  Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.Neo4jTemplate org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jTemplate() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jMappingContext' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.mapping.Neo4jMappingContext org.springframework.data.neo4j.config.Neo4jConfiguration.neo4jMappingContext() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityIndexCreator' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.mapping.EntityIndexCreator org.springframework.data.neo4j.config.Neo4jConfiguration.entityIndexCreator() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexProvider' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.springframework.data.neo4j.support.index.IndexProvider org.springframework.data.neo4j.config.Neo4jConfiguration.indexProvider() throws java.lang.Exception] threw exception; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'graphDatabaseService' is defined (Use --stacktrace to see the full trace)