我正在嘗試使用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