2014-05-05 100 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回购中为此解决方案创建另一个分支。

相关问题