2014-05-05 30 views
0

我正在嘗試使用Josh Long - Philip Sorst example來執行Angular SPA-Rest身份驗證和使用Neo4J作爲db的CRUD操作(非常棒的工作。 )。但是我陷入了一個很早的階段,我懷疑這不是我的錯。請幫助Neo4J-Angular-Spring愛好者。我的代碼可以找到here,它很容易運行只是克隆,並給予mvn spring-boot:runNullPointerException 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; 
    } 
} 
+0

我最初也遇到了這個問題,但是在添加@EnableTransactionManagement之後,它就消失了,請參閱我的測試項目:https://github.com/jexp/sdn-twitter-graph –

+0

不幸的是,我昨天失去了您的網絡研討會。感謝您的代碼,我很快會看看。你已經在xml中設置了Neo4j,我認爲這個技巧是通過''tx:annotation-driven mode =「proxy」/>'行執行的。如果這個工作接下來想,我會嘗試從cineasts'Userdetails'實現中獲得,以使Spring Security能夠與Graph中的節點一起工作。你見過Spring Security Userdetails和Neo4j的更現代的實現嗎? – pv1

回答

0

你不應該重寫:

@Bean 
    public Neo4jTemplate neo4jTemplate() { 
    return new Neo4jTemplate(graphDatabaseService()); 
    } 

而且你可以嘗試添加註釋:

@EnableTransactionManagement 

到你的配置?

+0

謝謝你的回覆。這不幸沒有幫助。同樣的異常仍然拋出。 – pv1

0

某事告訴我,解決方案隱藏在某個地方here。我會放棄並讓你知道。

OK只有當您將Spring-data-neo4j的版本更改爲2.3.3.RELEASE時,此工作纔有效。如果您使用最新版本,則會出現與上述相同的問題。我想我應該開一個問題。

但這不是解決方案,因爲我想使用Neo4J服務器社區2.0.3來打開圖形以供可視化之後。此外,我不明白這個解決方案beanfactories,注入而不是autowired ???。不過,我會在我的github回購中爲此解決方案創建另一個分支。

相關問題