我正在尝试使用Josh Long - Philip Sorst example来执行Angular SPA-Rest身份验证和使用Neo4J作为db的CRUD操作(非常棒的工作。 )。但是我陷入了一个很早的阶段,我怀疑这不是我的错。请帮助Neo4J-Angular-Spring爱好者。我的代码可以找到here,它很容易运行只是克隆,并给予mvn spring-boot:run
NullPointerException TopLevelTransaction.markAsRollbackOnly Neo4J-Boot for findAll()方法
现在的问题是,我只为GraphRepository的findAll()方法得到以下异常。
Caused by: java.lang.NullPointerException: null
at org.neo4j.kernel.TopLevelTransaction.markAsRollbackOnly(TopLevelTransaction.java:93)
... 88 common frames omitted
,我会复制我的一些代码:
Neo4JConfig.java
@Configuration
@EnableNeo4jRepositories(basePackages = "demo.repository.neo4j")
public class Neo4JConfig extends Neo4jConfiguration {
public Neo4JConfig() {
setBasePackage("demo.model.neo4j");
}
@Bean(destroyMethod = "shutdown")
public GraphDatabaseService graphDatabaseService() {
return new GraphDatabaseFactory().newEmbeddedDatabase("data/demo.db");
}
@Bean
public Neo4jTemplate neo4jTemplate() {
return new Neo4jTemplate(graphDatabaseService());
}
}
NewsEntry.java
@NodeEntity
public class NewsEntry {
@GraphId
private Long id;
private String content;
public NewsEntry() {}
public NewsEntry(String b) {
this.content = b;
}
public Long getId() {
return this.id;
}
public String getContent() {
return this.content;
}
public void setId(Long id) {
this.id = id;
}
public void setContent(String content) {
this.content = content;
}
}
NewsEntryRepository的.java
public interface NewsEntryRepository extends GraphRepository<NewsEntry> {
}
NewsEntryController.java
@RestController
class NewsController {
@Autowired
private NewsEntryRepository newsEntryRepository;
@RequestMapping("/news")
List<NewsEntry> entries() {
List<NewsEntry> list = new ArrayList<NewsEntry>();
Iterable<NewsEntry> results = newsEntryRepository.findAll();
for (NewsEntry r : results) {
list.add(r);
}
return list;
}
@RequestMapping(value = "/news/{id}", method = RequestMethod.DELETE)
void remove(@PathVariable Long id) {
this.newsEntryRepository.delete(id);
return;
}
@RequestMapping(value = "/news/{id}", method = RequestMethod.GET)
NewsEntry entry(@PathVariable Long id) {
return this.newsEntryRepository.findOne(id);
}
@RequestMapping(value = "/news/{id}", method = RequestMethod.POST)
NewsEntry update(@PathVariable Long id, @RequestBody NewsEntry news) {
NewsEntry old = this.newsEntryRepository.findOne(id);
old = news;
return this.newsEntryRepository.save(old);
}
@RequestMapping(value = "/news", method = RequestMethod.POST)
NewsEntry add(@RequestBody NewsEntry news) {
this.newsEntryRepository.save(new NewsEntry(news.getContent()));
return news;
}
}
我最初也遇到了这个问题,但是在添加@EnableTransactionManagement之后,它就消失了,请参阅我的测试项目:https://github.com/jexp/sdn-twitter-graph –
不幸的是,我昨天失去了您的网络研讨会。感谢您的代码,我很快会看看。你已经在xml中设置了Neo4j,我认为这个技巧是通过''tx:annotation-driven mode =“proxy”/>'行执行的。如果这个工作接下来想,我会尝试从cineasts'Userdetails'实现中获得,以使Spring Security能够与Graph中的节点一起工作。你见过Spring Security Userdetails和Neo4j的更现代的实现吗? – pv1