我正在尝试在我的grails项目中使用spring-data-neo4j,但有很多版本存在冲突。
我正在使用以下依赖
编译org.springframework.data:spring-data-neo4j-rest:3.1.2.RELEASE
然后,如果我运行我的neo4j服务器2.1.2然后它给我错误
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jMappingContext' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Invocation of init method failed; nested exception is java.lang.NullPointerException
... 4 more
Caused by: java.lang.NullPointerException
... 4 more
如果我运行1.8.3 neo4j服务器,那么它似乎连接到服务器但又出现错误
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'typeRepresentationStrategyFactory' 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.typerepresentation.TypeRepresentationStrategyFactory org.springframework.data.neo4j.config.Neo4jConfiguration.typeRepresentationStrategyFactory() throws java.lang.Exception] threw exception; nested exception is org.neo4j.rest.graphdb.RestResultException: expected START or CREATE
"MATCH (ref:ReferenceNode {name:{name}}) RETURN ref"
^ at
SyntaxException
请让我知道我错过了什么,或者有人可以告诉我应该使用的确切版本。
Buildconfig.config:
//grails.plugin.location."neo4j" = "../grails-data-mapping/grails-plugins/neo4j"
grails.servlet.version = "3.0" // Change depending on target container compliance (2.5 or 3.0)
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
grails.project.work.dir = "target/work"
grails.project.target.level = 1.6
grails.project.source.level = 1.6
grails.server.port.http = 7575
//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.fork = [
// configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
// compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the test-app JVM, uses the daemon by default
test: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// configure settings for the run-app JVM
// TODO: workaround, for Neo4j plugin forked mode is currently not working. Reason: Neo4jSpringConfigurer is using
// "as Classs" which causes ClassLoader issues
run: false, //[maxMemory: 768, minMemory: 64, debug: true, maxPerm: 256, forkReserve:false],
// configure settings for the run-war JVM
war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
// configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]
grails.project.dependency.resolver = "maven"
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
excludes 'xml-apis', 'netty', 'stax-api', 'slf4j-jdk14','log4j-over-slf4j', 'logback-classic'
// uncomment to disable ehcache
// excludes 'ehcache'
}
log "warn" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
legacyResolve false // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
repositories {
inherits true
grailsPlugins()
grailsHome()
mavenLocal()
grailsCentral()
mavenCentral()
// uncomment the below to enable remote dependency resolution
// from public Maven repositories
//flatDir name:'myRepo', dirs:'/abc/def'
mavenRepo 'http://m2.neo4j.org/content/repositories/releases/'
}
neo4jVerison="1.9.8"
dependencies {
//compile("org.neo4j:neo4j-community:2.0.0-M06")
//compile(group: 'org.neo4j', name: 'neo4j', version: "$neo4jVersion")
//compile(group: 'org.neo4j.app', name: 'neo4j-server', version: "$neo4jVersion", classifier: 'static-web')
// this is required if DataSource.groovy uses url = "jdbc:neo4j:mem"
//runtime(group:"org.neo4j", name:"neo4j-kernel", version:neo4jVerison)
// next four lines are required if you're using embedded/ha *and* you want the webadmin available
//compile(group:"org.neo4j.app", name:"neo4j-server", version:neo4jVerison)
// grails dependencies do not properly support maven classifiers, therefor we'll copy that
// dependency to lib directory
//runtime(group:"org.neo4j.app", name:"neo4j-server", version:neo4jVerison, classifier:"static-web")
//runtime('com.sun.jersey:jersey-server:1.9')
//runtime('com.sun.jersey:jersey-core:1.9')
// add graphviz capabilities
//compile(group:"org.neo4j", name:"neo4j-graphviz", version: neo4jVerison)
//runtime (group:"org.neo4j", name:"neo4j-shell", version: neo4jVerison)
// uncomment following line if type=rest is used in DataSource.groovy
//compile 'org.neo4j:neo4j-rest-graphdb:2.0.0-M06'
/*compile 'org.springframework:spring-core:3.1.0.RELEASE'
compile 'org.springframework:spring-context:3.0.0.RELEASE'
compile 'org.springframework:spring-beans:3.0.2.RELEASE'
compile 'org.springframework.data:spring-data-neo4j:1.1.0.RELEASE'*/
compile 'javax.validation:validation-api:1.0.0.GA'
//compile 'org.neo4j:neo4j:2.0.3'
compile 'org.springframework.data:spring-data-neo4j-rest:3.1.2.RELEASE'
//compile 'org.springframework.data:spring-data-neo4j:3.1.2.RELEASE'
test "org.spockframework:spock-grails-support:0.7-groovy-2.0"
}
plugins {
//compile ":neo4j:2.0.0-M02"
compile ":scaffolding:2.0.1"
runtime ":jquery:1.10.2.2"
runtime ":resources:1.2.1"
test(":spock:0.7") {
exclude "spock-grails-support"
}
// compile ":geb:0.9.0-RC-1"
// Uncomment these (or add new ones) to enable additional resources capabilities
//runtime ":zipped-resources:1.0"
//runtime ":cached-resources:1.0"
//runtime ":yui-minify-resources:0.1.4"
build ":tomcat:7.0.50"
// compile ':cloud-support:1.0.8'
// compile ':webxml:1.4.1'
}
}
用于弹簧设置的和resources.xml
<?xml version="1.0"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" 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.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.2.xsd">
<!-- REST Connection to Neo4j server -->
<bean id="graphDatabaseService"
class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg value="http://localhost:7474/db/data" />
</bean>
<!-- Neo4j configuration (template) -->
<neo4j:config graphDatabaseService="graphDatabaseService" />
<!-- Package w/ automagic repositories -->
<neo4j:repositories base-package="sample" />
</beans>
我正在使用grails开发并使用在localhost:7474上运行的neo4j 2.1.2版本,我正在使用休息服务进行数据库连接
所以对于neo4j 2.1.2我得到了以下异常。
14 [localhost-startStop-1] ERROR org.codehaus.groovy.grails.web.context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'communityCentreRepository': 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: Invocation of init method failed; nested exception is java.lang.NullPointerException
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'communityCentreRepository': 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: Invocation of init method failed; nested exception is java.lang.NullPointerException
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: 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: Invocation of init method failed; nested exception is java.lang.NullPointerException
... 4 more
Caused by: 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: Invocation of init method failed; nested exception is java.lang.NullPointerException
... 4 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jMappingContext' defined in class org.springframework.data.neo4j.config.Neo4jConfiguration: Invocation of init method failed; nested exception is java.lang.NullPointerException
... 4 more
Caused by: java.lang.NullPointerException
... 4 more