Comments (4)
Upon further investigation, it looks as though this only occurs when enabling Spring Data Neo4j repositories. I have created a simple repo to reproduce this but unfortunately im unable to push the repo to github as im behind a corporate firewall. Appologies but I will post each file here:
App.java
package com.mypackage;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan("com.mypackage")
@EnableAutoConfiguration
public class App
{
public static void main(String args[])
{
SpringApplication.run(App.class, args);
}
}
CustomNeo4jConfiguration.java
package com.mypackage;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.rest.graphdb.RestGraphDatabase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.data.neo4j.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.data.neo4j.support.DelegatingGraphDatabase;
import org.springframework.data.neo4j.support.Neo4jTemplate;
@Configuration
//@EnableNeo4jRepositories("com.mypackage")
public class CustomNeo4jConfiguration
{
GraphDatabaseService localDatabaseService;
/*@Bean
@DependsOn("graphDatabase")
public Neo4jTemplate neo4jTemplate()
{
return new Neo4jTemplate(graphDatabase());
}*/
@Bean
@Autowired
@DependsOn("graphDatabaseService")
public GraphDatabase graphDatabase()
{
if (localDatabaseService instanceof GraphDatabase) return (GraphDatabase) localDatabaseService;
return new DelegatingGraphDatabase(localDatabaseService);
}
@Bean
public GraphDatabaseService graphDatabaseService()
{
if (this.localDatabaseService == null)
{
String remoteDBURL = "http://localhost:7474/db/data";
System.setProperty("org.neo4j.rest.read_timeout","30");
System.setProperty("org.neo4j.rest.connect_timeout","30");
System.setProperty("org.neo4j.rest.driver","neo4j-rest-graphdb/2.0.1");
System.setProperty("org.neo4j.rest.stream","true");
System.setProperty("org.neo4j.rest.batch_transaction","false");
System.setProperty("org.neo4j.rest.logging_filter","false");
this.localDatabaseService = new RestGraphDatabase(remoteDBURL);
}
return this.localDatabaseService;
}
}
MyNodeEntity.java
package com.mypackage;
import org.springframework.data.neo4j.annotation.GraphId;
import org.springframework.data.neo4j.annotation.NodeEntity;
@NodeEntity
public class MyNodeEntity
{
@GraphId
Long id;
}
MyNodeRepository.java
package com.mypackage;
import org.springframework.data.neo4j.repository.GraphRepository;
public interface MyNodeRepository extends GraphRepository<MyNodeEntity>
{
}
MyService.java
package com.mypackage;
import org.neo4j.graphdb.GraphDatabaseService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class MyService implements InitializingBean
{
@Autowired
GraphDatabaseService gds;
public void afterPropertiesSet() throws Exception
{
System.out.println("Success = " + gds.getAllNodes().iterator().next() );
}
}
pom.xml
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>0.5.0.M6</version>
<!-- <version>1.0.0.RC1</version> -->
</parent>
<groupId>com.mypackage</groupId>
<artifactId>neo4j-remote</artifactId>
<version>1.0-SNAPSHOT</version>
<name>neo4j-remote</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>3.0.0.RC1</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-rest-graphdb</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>neo4j-release-repository</id>
<name>Neo4j Maven 2 release repository</name>
<url>http://m2.neo4j.org/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>neo4j-snapshot-repository</id>
<name>Neo4j Maven 2 snapshot repository</name>
<url>http://m2.neo4j.org/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
<repository>
<id>Sun</id>
<url>http://download.java.net/maven/2</url>
</repository>
</repositories>
</project>
To run this:
-
Startup a local instance of Neo4j server on localhost:7474 (ensure you have a least one node in it)
-
Build the app by running
mvn clean package
-
Run the app with:
java -jar target\neo4j-remote-1.0-SNAPSHOT.jar
-
You should see the app connect and dump out the line:
Success = http://localhost:7474/db/data/node/0
-
Now in the
CustomNeo4jConfiguration
uncomment the following two sections:@EnableNeo4jRepositories("com.mypackage")
and
@Bean @DependsOn("graphDatabase") public Neo4jTemplate neo4jTemplate() { return new Neo4jTemplate(graphDatabase()); }
- Now re-build and run again and you should see the NullPointerException thrown
from java-rest-binding.
Is there a work-around for this issue? Or is using a RestGraphDatabase and spring-boot just plain broken?
from java-rest-binding.
Andrew it is not broken at all. Just wrapping a RestGraphDatabase in a DelegatingDatabase is nothing anyone would ever do. Just use SpringRestGraphDatabase(url)
See this example: https://github.com/neo4j-contrib/developer-resources/tree/gh-pages/language-guides/java/spring-data-neo4j
from java-rest-binding.
@jexp Thanks much. Very helpful.
from java-rest-binding.
Related Issues (20)
- Provide a release which is compatible with Neo4j 2.0.0-RC1 HOT 2
- Provides a version for 2.0.0 server HOT 3
- Unable to add label using Neo4j Rest API - Error reading as JSON ''
- Handling of cypher results with nested collections/maps with nodes and relationships
- RuntimeException thrown when executing cypher in a batch mode
- Property URLs not sanity checked HOT 1
- lack of Documentation
- could you please uograde the jersey-client version HOT 3
- 2.0.1 conflict with neo4j-kernel's package version of org.neo4j.helpers.collection.WrappingResourceIterator
- Create node with labels
- 2.0.2 release HOT 5
- Unit testing class not packaged? HOT 3
- Implement schema support
- NullPointerException in ExecutionEngine HOT 1
- Getting a 502 Bad gateway while saving nodes - RANDOMLY HOT 2
- cypher query endpoint deprecated. HOT 1
- how to use java to exeute cypher through the network?(not embedded) HOT 1
- Maven version 2.0.1 HOT 1
- char[] stored as string HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from java-rest-binding.