Spring Data Neo4j: Using the server with an embedded - neo4j

I'm trying to configure my application context in order to be able to use the Neo4j server with an embedded graph in my app without much success. I'm using Spring Data at the same time (both Mongo and Neo4j repositories approach). This is my application-context, which isn't running:
<context:component-scan base-package="org.domain.team.project.*"/>
<mongo:repositories base-package="org.domain.team.project.data.repositories.mongodb"/>
<!-- Neo4j -->
<!-- <neo4j:config storeDirectory="/data/production/graph.db"/> -->
<neo4j:repositories base-package="org.domain.team.project.data.repositories.neo4j"/>
<neo4j:config graphDatabaseService="graphDatabaseService" />
<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase"
destroy-method="shutdown">
<constructor-arg index="0" value="/data/production/graph.db" />
<constructor-arg index="1">
<map><entry key="enable_remote_shell" value="true"/></map>
</constructor-arg>
</bean>
<bean id="serverWrapper" class="org.neo4j.server.WrappingNeoServerBootstrapper"
init-method="start" destroy-method="stop">
<constructor-arg ref="graphDatabaseService"/>
</bean>
If I don't use this approach and specify simply the store directory (commented line) everything runs fine. I suspect it's a version between SDN and neo4j-server issue. This is my POM:
<properties>
<spring.data.mongo.version>1.1.0.RELEASE</spring.data.mongo.version>
<spring.data.neo4j.version>2.1.0.RELEASE</spring.data.neo4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>${spring.data.mongo.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>${spring.data.neo4j.version}</version>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<version>1.8.2</version>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<classifier>static-web</classifier>
<version>1.8.2</version>
</dependency>
</dependencies>
Its parent has as a dependency Spring(core,context,test) 3.2.0 Release.
The concrete error being displayed is:
Caused by: java.lang.NoSuchFieldError: query_cache_size
at org.neo4j.cypher.ExecutionEngine.org$neo4j$cypher$ExecutionEngine$$getQueryCacheSize(ExecutionEngine.scala:95)
at org.neo4j.cypher.ExecutionEngine$$anon$1.<init>(ExecutionEngine.scala:91)
at org.neo4j.cypher.ExecutionEngine.<init>(ExecutionEngine.scala:91)
at org.neo4j.cypher.javacompat.ExecutionEngine.<init>(ExecutionEngine.java:54)
at org.neo4j.cypher.javacompat.ExecutionEngine.<init>(ExecutionEngine.java:44)
at org.springframework.data.neo4j.support.query.CypherQueryEngine.<init>(CypherQueryEngine.java:42)
at org.springframework.data.neo4j.support.DelegatingGraphDatabase.createCypherQueryEngine(DelegatingGraphDatabase.java:217)
at org.springframework.data.neo4j.support.DelegatingGraphDatabase.queryEngineFor(DelegatingGraphDatabase.java:190)
at org.springframework.data.neo4j.support.MappingInfrastructureFactoryBean.afterPropertiesSet(MappingInfrastructureFactoryBean.java:146)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483)
... 47 more
which as far as I am concerned, should be no problem as the default value is 100. The SDN doc does not talk too much about it. Any suggestions?
Thank you all in advance.

Looks like version compatibility issue. For me below combination is working fine
spring-data-neo4j : 2.1.0.RC4
spring-data-mongodb : 1.1.0.RELEASE
neo4j-server : 1.8
static-web : 1.8
Further, I am using-
Spring framework version : 3.1.2.RELEASE
Neo4j version : 1.8
mongodb version : 2.2.2
mongo-java-driver : 2.9.1
slf4j : 1.7.2

Related

weld-junit5 with weld 3

Recently we upgarde Weld to 3.0.3.Final (with is the one in Wildfly 12). Now weld-junit5 1.3.1.Final (the most recent version) throws an exception
java.lang.NoSuchMethodError: javax.enterprise.inject.spi.AfterBeanDiscovery.addBean()Ljavax/enterprise/inject/spi/configurator/BeanConfigurator;
We added weld-se-core to dependency management:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>3.0.3.Final</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
This overrules the default Version of weld-se-core 2.4.8.Final, which is defined in weld-junit5. But it seems that weld-junit5 depends on the structure of weld 2.x
weld-junit5 states on its github page that weld 3 is supported but there is no description how to use it. I have found this in the POM of weld-junit5:
<profile>
<id>weld3</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>env.WELD_JUNIT_PROFILE</name>
<value>weld3</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>org.jboss.weld.module</groupId>
<artifactId>weld-ejb</artifactId>
<version>${version.weld}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
But I did not get this profile activated.
How can this be solved?
With weld-se-shaded instead of weld-se-core it works.

Unable to obtain lock on store lock file

I'm building a project with embedded Neo4j and Spring Data, and i'm having problems with file lock, i'm getting the exception:
Caused by: org.neo4j.kernel.StoreLockException: Unable to obtain lock on store lock file: data/graph.db/store_lock. Please ensure no other process is using this database, and that the directory is writable (required even for read-only access)
at org.neo4j.kernel.StoreLocker.checkLock(StoreLocker.java:78)
at org.neo4j.kernel.StoreLockerLifecycleAdapter.start(StoreLockerLifecycleAdapter.java:44)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:503)
... 47 more
There is no other processes using the data/graph.db, and it's not a permission problem, the data folder is created during runtime, and i already tried change the permissions to 777.
my applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/data/neo4j
http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-4.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<context:spring-configured />
<context:annotation-config />
<tx:annotation-driven mode="proxy"/>
<neo4j:repositories base-package="br.com.teste.repository" />
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="br.com.teste.model"/>
<bean id="graphDatabaseService" class="org.springframework.data.neo4j.support.GraphDatabaseServiceFactoryBean"
destroy-method="shutdown" scope="singleton">
<constructor-arg value="data/graph.db"/>
<constructor-arg>
<map>
<entry key="enable_remote_shell" value="true"/>
</map>
</constructor-arg>
</bean>
<bean id="serverWrapper" class="org.neo4j.server.WrappingNeoServer"
init-method="start" destroy-method="stop">
<constructor-arg ref="graphDatabaseService" />
</bean>
my pom.xml
<dependencies>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- Spring Data Neo4j -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j-aspects</artifactId>
<version>3.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.4</version>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<classifier>static-web</classifier>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<version>2.0.1</version>
</dependency>
<!-- Apache Commons Lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.4</version>
</dependency>
<!-- JSON Resolver -->
<dependency>
<groupId> org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>
<!-- JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
</dependencies>
Why i'm still getting the exception of Unable to obtain lock?
Edit:
I was having so much problems trying to config the embedded database, so i tried the REST wich was so much easier to config, and is fully working now.

Exposing Neo4J REST within TomCat

I have an SDN 2.3.1 application running 1.9 Neo4J embedded which is deployed on Tomcat 7. All good when running both embedded and rest. However, I'm now looking to try and expose the REST interface having followed This Post so that I cuse Linkurious to explore the embedded data.
The exception I get on deployment is:
com.sun.jersey.api.container.ContainerException: No WebApplication provider is present
My XML config is
<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase" destroy-method="shutdown">
<constructor-arg index="0" value="${neo4j.datastore}"/>
<constructor-arg index="1">
<map>
<entry key="allow_store_upgrade" value="true"/>
<entry key="enable_remote_shell" value="true"/>
</map>
</constructor-arg>
</bean>
<bean id="serverWrapper" class="org.neo4j.server.WrappingNeoServer" init-method="start" destroy-method="stop">
<constructor-arg ref="graphDatabaseService"/>
</bean>
I have the static-web and neo4j-server in my pom.xml
My guess is it's a conflict with Jetty and Tomcat around who's allowed to deploy to a context. Is my config even possible and if so, what step might I be missing?
Missing transitive dependency on Jersey which I didn't spot in documentation.
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.17.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.17.1</version>
</dependency>
The web admin interface is throwing an exception but I can at least run embedded and expose a RESTful interface to Neo4J- Yay!
Thanks to this post for the pointer

Web interface neo4j embedded remote not working

I am running Neo4j in embedded mode on a remote Linux server... everything works well except the ability to connect to the web interface /host:7474/webadmin/
Using Neo4j 1.8.2 Major Stable Version
Relevant POM artifacts:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>2.2.0.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<version>1.8.2</version>
<exclusions>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>org.mortbay.jetty</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<version>1.8.2</version>
<exclusions>
<exclusion>
<artifactId>logback-classic</artifactId>
<groupId>ch.qos.logback</groupId>
</exclusion>
</exclusions>
<classifier>static-web</classifier>
</dependency>
Neo4j config XML file:
<context:annotation-config />
<context:spring-configured />
<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase">
<constructor-arg value="#{props['neo4j.location']}" />
<constructor-arg>
<map>
<entry key="enable_remote_shell" value="true" />
</map>
</constructor-arg>
</bean>
<neo4j:config graphDatabaseService="graphDatabaseService" />
<bean id="serverWrapper" class="org.neo4j.server.WrappingNeoServerBootstrapper"
init-method="start" destroy-method="stop">
<constructor-arg ref="graphDatabaseService" />
</bean>
<tx:annotation-driven mode="aspectj"
transaction-manager="transactionManager" />
<neo4j:repositories base-package="com.writelife.server.graph.repository"
repository-impl-postfix="CustomImpl" />
neo4j-server.properties file:
# location of the database directory
org.neo4j.server.database.location=data/graph.db
org.neo4j.server.webserver.address=0.0.0.0
org.neo4j.server.webserver.port=7474
# Turn https-support on/off
org.neo4j.server.webserver.https.enabled=true
# https port (for all data, administrative, and UI access)
org.neo4j.server.webserver.https.port=7473
# Certificate location (auto generated if the file does not exist)
org.neo4j.server.webserver.https.cert.location=conf/ssl/snakeoil.cert
# Private key location (auto generated if the file does not exist)
org.neo4j.server.webserver.https.key.location=conf/ssl/snakeoil.key
org.neo4j.server.webserver.https.keystore.location=data/keystore
org.neo4j.server.webadmin.rrdb.location=data/rrd
org.neo4j.server.webadmin.data.uri=/db/data/
# REST endpoint of the administration API (used by Webadmin)
org.neo4j.server.webadmin.management.uri=/db/manage/
# Low-level graph engine tuning file
org.neo4j.server.db.tuning.properties=conf/neo4j.properties
org.neo4j.server.http.log.enabled=false
org.neo4j.server.http.log.config=conf/neo4j-http-logging.xml
DB location on the file system:
/opt/neo4j-community-1.8.2/data/graph.db
Can someone explain me what am I doing wrong? How can I monitor the web interface in that consultation?
Thanks
Did you follow the instructions here?
http://docs.neo4j.org/chunked/stable/server-embedded.html
I think the neo4j-server.properties are not used. The properties you pass in to the graphdatabase are used for the database only not for the web-ui / http-server on top of that.
I think you can pass them in to the WrappingNeoServerBootstrapper
Seems to be working with a Server-Configurator. There is a also a property-file based Server configurator PropertyFileConfigurator which is passed the neo4j-server.properties file as a File object in its constructor.
I think your maven config misses the static resources too.
<dependencies>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<version>1.8.1</version>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<classifier>static-web</classifier>
<version>1.8.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>neo4j-snapshot-repository</id>
<name>Neo4j Maven 2 snapshot repository</name>
<url>http://m2.neo4j.org/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

A universal match pattern ('/**') is defined before other patterns in the filter chain, causing them to be ignored

I am running into this issue with Spring 3.1.3 release and with the following application context file. I am not quite sure why does this occur. Have looked into most of the posts related to this. I dont think I have a version mismatch.
Application Context file:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<security:http auto-config='true' entry-point-ref="casEntryPoint" >
<security:intercept-url pattern="/panelpipeline/**" access="ROLE_USER"/>
<security:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
</security:http>
<bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties">
<property name="service"
value="https://seqdws1/cas/j_spring_cas_security_check" />
<property name="sendRenew" value="false" />
</bean>
<security:http entry-point-ref="casEntryPoint">
<security:custom-filter position="CAS_FILTER"
ref="casFilter" />
</security:http>
<bean id="casFilter"
class="org.springframework.security.cas.web.CasAuthenticationFilter">
<property name="authenticationManager" ref="authenticationManager" />
</bean>
<bean id="casEntryPoint"
class="org.springframework.security.cas.web.CasAuthenticationEntryPoint">
<property name="loginUrl" value="https://seqdws1/cas/login" />
<property name="serviceProperties" ref="serviceProperties" />
</bean>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider
ref="casAuthenticationProvider" />
</security:authentication-manager>
<bean id="casAuthenticationProvider"
class="org.springframework.security.cas.authentication.CasAuthenticationProvider">
<property name="userDetailsService" ref="userService" />
<property name="serviceProperties" ref="serviceProperties" />
<property name="ticketValidator">
<bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
<constructor-arg index="0" value="https://seqdws1/cas" />
</bean>
</property>
<property name="key" value="an_id_for_this_auth_provider_only" />
</bean>
<security:user-service id="userService">
<security:user name="joe" password="joe" authorities="ROLE_USER" />
</security:user-service>
<!-- <security:authentication-manager> <security:authentication-provider>
<security:user-service> <security:user name="jimi" password="jimispassword"
authorities="ROLE_USER, ROLE_ADMIN" /> <security:user name="bob" password="bobspassword"
authorities="ROLE_USER" /> </security:user-service> </security:authentication-provider>
</security:authentication-manager> -->
POM dependencies
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwtVersion}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
<classifier>sources</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-cas</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
</dependencies>
The configuration you've posted has two <http> elements, neither of which has a pattern attribute so both are implicitly defined to match all requests. The second one will overwrite the first.
That doesn't necessarily explain why you are seeing this message (since it should normally apply to filters within a single chain), but it is definitely a mistake.
You should also probably remove auto-config='true' unless you know for sure that you want the extra filters which it implicitly adds.

Resources