有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在tomcat上部署多个版本时java Spring数据Neo4j NullPointerException

我正在使用SpringMVC(4.2.0.RELEASE)开发一个JavaREST服务,包括一个Neo4j数据库。因此,使用了弹簧数据Neo4j(4.1.1.版本)

SDN配置如下所示:

@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();
    }

}

该应用程序部署在生产环境中的Tomcat7上。如果只部署了应用程序的一个版本,并且没有填写版本标志,那么一切都会很顺利

对于零停机部署,我希望使用tomcat上的版本标志来部署多个版本。如果我这样做,应用程序将不再工作,因为org.neo4j.ogm.context.RestModelMapper中有一个NullPointerException

堆栈跟踪:

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:?]

只有在tomcat上使用版本标志时,才会出现此问题。有人知道这里有什么问题吗


共 (1) 个答案

  1. # 1 楼答案

    通过更改OGM HTTP驱动程序的版本和Spring数据Neo4j依赖关系,我最终解决了这个问题

    <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>
    

    有了这些设置,带有Tomcat版本标志https://tomcat.apache.org/tomcat-7.0-doc/config/context.html的部署现在可以工作了