使用findAll()
中的GraphRepository<Account>
:
context = new ClassPathXmlApplicationContext("spring/spring-config.xml");
accountService = (AccountService) context.getBean("accountService");
//getAll(){return accountRepository.findAll()}
accountService.getAll().forEach(account -> System.out.println(account));
(顺便说一句,我的帐户服务中的所有其他功能都有效)
我收到此错误:
Exception in thread "main" org.neo4j.graphdb.TransactionFailureException:
Failed to mark transaction as rollback only.
我尝试用Spring Data Neo4J repository findAll() results in a nullpointerexception解决问题,
所以我在spring-config.xml中添加<tx:annotation-driven mode="proxy"/>
但它并没有解决我的问题。
这里是我的github回购:https://github.com/mzober/springContextWorld/tree/CollectorManager_ErrorBranch
这是我的spring-config.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:tx="http://www.springframework.org/schema/tx"
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.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:annotation-config/>
<context:spring-configured/>
<context:component-scan base-package="com.mz.springContextWorld.domain"/>
<context:component-scan base-package="com.mz.springContextWorld.repositories"/>
<context:component-scan base-package="com.mz.springContextWorld.gui.listener"/>
<context:component-scan base-package="com.mz.springContextWorld.gui.components"/>
<context:component-scan base-package="com.mz.springContextWorld.gui.creational"/>
<context:component-scan base-package="com.mz.springContextWorld.services"/>
<neo4j:config storeDirectory="target/neo4j-db-plain"
base-package="com.mz.springContextWorld.domain"/>
<neo4j:repositories base-package="com.mz.springContextWorld.repositories"/>
<tx:annotation-driven mode="proxy"/>
如果我要发布更多代码,请写一条评论。
帮助。
答案 0 :(得分:0)
这可能与问题有关:https://jira.spring.io/browse/DATAGRAPH-531。如果是这种情况,则需要更改
service.findAll()
为:
service.findAll().as(Collection.class)
...并且回滚异常应该消失。