我是 Neo4j 和 Spring 的新手。我已经尽我所能做我的功课——如果有一个神奇的文档,我在此过程中错过了所有的答案,我最诚挚的歉意。
目的是使用 spring-data-neo4j 与 Neo4j 数据库进行交互。我已经按照良好关系中的指南取得了一些成功,但想从书中使用的 1.6.M02 版本继续前进。
虽然 Maven 存储库中没有为 spring-data-neo4j 2.2.1指定它,但 Maven 包含的 Neo4j 版本是 1.8.1,据我所知,这是正确的版本。这也按应有的方式引入了 Spring 框架(3.1.4)。所以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>yet</groupId>
<artifactId>another</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cinecopy</name>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.0</version>
</dependency>
</dependencies>
</project>
那么我们就有了最简单的测试用例:
@ContextConfiguration(locations = "classpath:testContext.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class SomeTest {
@Autowired
Neo4jTemplate template;
@Test
@Transactional
public void badNews() {
Person add = new Person();
add.setName("What.");
add = template.save(add);
}
}
指的是testContext.xml
:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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:neo4j="http://www.springframework.org/schema/data/neo4j"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/data/neo4j
http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd">
<context:annotation-config/>
<neo4j:config storeDirectory="target/config-test"/>
</beans>
这给了我(完整的跟踪):
Failed to load ApplicationContext [...]
Cannot load configuration class: org.springframework.data.neo4j.config.Neo4jConfiguration
我觉得这很奇怪,因为事情似乎可以正常工作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>yet</groupId>
<artifactId>another</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>cinecopy</name>
<dependencies>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>1.6.M02</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>
任何指导将不胜感激!