1

I am bootstrapping a new project from the Accessing Neo4j Data with REST example. The example uses an embedded database rather than a standalone neo4j server, but I would like to use the Neo4J webadmin interface for visualisation of my data. How do I enable the webadmin interface starting from this configuration?

(They got WrappingNeoServerBootstrapper working in use WrappingNeoServerBootstrapper with spring-data-neo4j but a lot of knowledge is omitted from the answer, e.g. it is not even mentioned where to place to the configuration. Being new to POMs, Spring Boot and Neo4j I therefore can't make use of that answer.)

Community
  • 1
  • 1
Kasper Marstal
  • 342
  • 1
  • 15
  • There is already a similar question http://stackoverflow.com/questions/21658546/how-can-i-use-the-webadmin-interface-with-an-embedded-neo4j-2-0-instance – mavarazy Jan 11 '15 at 09:00
  • Thank you for your suggestion. The top answer in the question you referenced suggests a configuration based on the webapp folder in addition to the pom. As far as I understand using Spring Boot and the embedded tomcat server circumvents the need for a webapp folder and the like so the configuration endpoints of the two questions are not identical. My question is specifically about launching the webadmin interface starting from the "Accessing Neo4j Data with REST" code which reduces the noise of the scope of the question. Any help getting this to work is greatly appreciated! – Kasper Marstal Jan 11 '15 at 17:12

1 Answers1

3

The example you are using needs some tweaking to enable the Neo4j browser. I started from a different example, the Accessing Data with Neo4j example and it worked well.

You will need to do the following:

  1. Change the version on your spring boot pom to 1.2.1.Release:

     <parent>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
         <version>1.2.1.RELEASE</version>
     </parent>
    
  2. Add dependencies for Neo4jServer:

    <dependency>
        <groupId>org.neo4j.app</groupId>
        <artifactId>neo4j-server</artifactId>
        <version>2.1.5</version>
    </dependency>
    <dependency>
        <groupId>org.neo4j.app</groupId>
        <artifactId>neo4j-server</artifactId>
        <version>2.1.5</version>
        <classifier>static-web</classifier>
    </dependency>
    
  3. Implement the Spring Boot command line runner in your Application.class:

     public class Application extends Neo4jConfiguration implements CommandLineRunner{
    
  4. Autowire a reference to your GraphDatabaseService in your Application.class:

    @Autowired
    GraphDatabaseService db;
    
  5. @Override the run method from CommanLineRunner in your Application.class:

    @Override
    public void run(String... strings) throws Exception {
        // used for Neo4j browser
        try {
            WrappingNeoServerBootstrapper neoServerBootstrapper;
            GraphDatabaseAPI api = (GraphDatabaseAPI) db;
    
            ServerConfigurator config = new ServerConfigurator(api);
            config.configuration()
                .addProperty(Configurator.WEBSERVER_ADDRESS_PROPERTY_KEY, "127.0.0.1");
            config.configuration()
                .addProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY, "8686");
    
            neoServerBootstrapper = new WrappingNeoServerBootstrapper(api, config);
            neoServerBootstrapper.start();
        } catch(Exception e) {
            //handle appropriately
        }
        // end of Neo4j browser config
    }
    

When you are all done, your Application.class should look like this:

package hello;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.kernel.GraphDatabaseAPI;
import org.neo4j.server.WrappingNeoServerBootstrapper;
import org.neo4j.server.configuration.Configurator;
import org.neo4j.server.configuration.ServerConfigurator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.data.neo4j.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;

@Configuration
@EnableNeo4jRepositories
@Import(RepositoryRestMvcConfiguration.class)
@EnableAutoConfiguration
public class Application extends Neo4jConfiguration implements CommandLineRunner{

    public Application() {
        setBasePackage("hello");
    }

    @Bean(destroyMethod = "shutdown")
    public GraphDatabaseService graphDatabaseService() {
        return new GraphDatabaseFactory().newEmbeddedDatabase("target/hello.db");
    }

    @Autowired
    GraphDatabaseService db;



    @Override
    public void run(String... strings) throws Exception {
        // used for Neo4j browser
        try {
            WrappingNeoServerBootstrapper neoServerBootstrapper;
            GraphDatabaseAPI api = (GraphDatabaseAPI) db;

            ServerConfigurator config = new ServerConfigurator(api);
            config.configuration()
                    .addProperty(Configurator.WEBSERVER_ADDRESS_PROPERTY_KEY, "127.0.   0.1");
            config.configuration()
                    .addProperty(Configurator.WEBSERVER_PORT_PROPERTY_KEY, "8686");

            neoServerBootstrapper = new WrappingNeoServerBootstrapper(api, config);
            neoServerBootstrapper.start();
        } catch(Exception e) {
            //handle appropriately
        }
        // end of Neo4j browser config
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }


}

The Neo4j browser will be available on the host and port configured in your run() method.

George S
  • 630
  • 1
  • 4
  • 6
  • I should mention I only intend to use this for development. I think this actually starts a second embedded http server to serve the Neo4j browser. – George S Jan 23 '15 at 17:23
  • Thanks a bunch George, your time and answer is much appreciated. – Kasper Marstal Jan 25 '15 at 23:15
  • 1
    Did anyone already tried to adapt this to latest spring boot 1.4 version? I tried to upgrade my code, but it seems this useful inclusion in not working anymore. :( – Michele Sacchetti Apr 25 '16 at 12:50