我正在使用Spring Data Neo4j,在Spring中创建了一个应用程序 . 我可以在JUnit测试用例的帮助下运行我的应用程序 . 但每次运行我的测试用例时,它都会在使用 <neo4j:config storeDirectory="target/neo4j-db"/>
指定的目录路径中创建一个新数据库 . 这将在我的工作空间存在于Eclipse中的相同位置创建db .
我在我的ubuntu中安装了Neo4j debian软件包,默认情况下在 /var/lib/neo4j/data/graph.db
中有数据库 . 我希望我的应用程序使用此数据库,而不是在 target/neo4j-db
中创建一个 . 我试图通过 /var/lib/neo4j/data/graph.db
替换 target/neo4j-db
并且已经允许读取和写入数据库 . 但它不起作用 .
这个配置有什么问题?我错过了什么吗?
1 回答
要针对Neo4j DB运行JUnit测试,您有3个选择
使用Neo4j使用的 local 文件夹 . 为此,您必须在运行测试之前停止Neo4j服务器 . 如果您正在使用SpringJUnit4ClassRunner.class运行测试,并且想要确保在更改之后未还原您的更改,则必须在所需的方法上放置
@Rollback(false)
. 这必须完成,因为SpringJUnit4ClassRunner.class将回滚在测试期间对数据库所做的所有更改 .使用 REST 方法(并再次使用
@Rollback(false)
用于SpringJUnit4ClassRunner.class的技巧) . 为了使其与本地方法相反,您必须在运行测试之前启动Neo4j服务器 . 您还必须像这样配置您的xml文件:<neo4j:config graphDatabaseService="graphDatabaseService"/> <bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase"> <constructor-arg value="http://localhost:7474/db/data/" index="0" /> </bean>
<neo4j:config graphDatabaseService="graphDatabaseService"/> <bean id="graphDatabaseService" class="org.neo4j.test.ImpermanentGraphDatabase" destroy-method="shutdown"/>