K.E. K.E. - 12 days ago 6
Java Question

Spring Data Neo4j NullPointerException when deploying multiple versions on tomcat

I am working on a Java Rest Service with Spring MVC (4.2.0.RELEASE) including a Neo4j database. Therefore Spring Data Neo4j (4.1.1.RELEASE) is used.

The SDN configuration looks like this:

@Configuration
@ComponentScan(basePackages = { "com.xxx.yyy" })
@EnableNeo4jRepositories(basePackages = "com.xxx.yyy.dao.repo")
@EnableTransactionManagement
public class Neo4jConfig extends Neo4jConfiguration {

@Autowired
private ApplicationProperties properties;

@Bean
public SessionFactory getSessionFactory() {
return new SessionFactory(getConfiguration(), "com.xxx.yyy.dao.beans");
}

@Bean
public Neo4jOperations neo4jTemplate() throws Exception {
return new Neo4jTemplate(getSession());
}

@Bean
public org.neo4j.ogm.config.Configuration getConfiguration() {
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();

config.driverConfiguration().setDriverClassName(this.properties.getNeo4jDriver())
.setURI(this.properties.getNeo4jEndpoint())
.setCredentials(this.properties.getNeo4jUser(), this.properties.getNeo4jPassword());

return config;
}

@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
return super.getSession();
}

}


The application is deployed on a Tomcat7 in production environment. Everything works like a charm if there is only one version of the application deployed and the version flag is not filled in.

For a zero downtime deployment I want to use the version flag on the tomcat to deploy multiple versions. If I do so the application is not working anymore because of a
NullPointerException
in the
org.neo4j.ogm.context.RestModelMapper
.

Stacktrace:

java.lang.NullPointerException
at org.neo4j.ogm.context.RestModelMapper.mapEntity(RestModelMapper.java:153) ~[neo4j-ogm-core-2.0.1.jar:?]
at org.neo4j.ogm.context.RestModelMapper.map(RestModelMapper.java:76) ~[neo4j-ogm-core-2.0.1.jar:?]
at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQueriesDelegate.java:94) ~[neo4j-ogm-core-2.0.1.jar:?]
at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQueriesDelegate.java:73) ~[neo4j-ogm-core-2.0.1.jar:?]
at org.neo4j.ogm.session.Neo4jSession.query(Neo4jSession.java:313) ~[neo4j-ogm-core-2.0.1.jar:?]


This problem occurs only if I use the version flag on tomcat. Does anyboby know what is the problem here?

Answer

I finally solved this issue by changing the version of the OGM HTTP Driver and the Spring Data Neo4j dependency.

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-neo4j</artifactId>
    <version>4.1.4.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-ogm-http-driver</artifactId>
    <version>2.0.5</version>
</dependency>

With this settings the deployment with the Tomcat version flag https://tomcat.apache.org/tomcat-7.0-doc/config/context.html is now working.