Spring Data Neo4j - 如何让WrappingNeoServerBootstrapper监听0.0.0.0

时间:2012-11-17 17:27:38

标签: neo4j spring-data-neo4j

一直试图让WrappingNeoServerBootstrapper在0.0.0.0而不是localhost上启动Neo4j WebAdmin接口。尝试指定JAVA_OPTS(例如-Dorg.neo4j.server.webserver.address = 0.0.0.0)的所有形式,在WrappingNeoServerBootstrapper的第二个构造函数参数中传递我自己的Config - 但它总是侦听localhost。希望有人有解决方案或例子。这是我的Spring配置 - 回归基础知识。提前谢谢。

<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase" destroy-method="shutdown">
    <constructor-arg index="0" value="${com.calendr.neo4jDataDir}"/>
    <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.WrappingNeoServerBootstrapper" init-method="start" destroy-method="stop">
     <constructor-arg ref="graphDatabaseService"/>
</bean>

1 个答案:

答案 0 :(得分:1)

我在阅读完Neo代码后想通了。这是我最后的工作配置。

<neo4j:config graphDatabaseService="graphDatabaseService"/>

<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase" destroy-method="shutdown">
    <constructor-arg index="0" value="${com.mycompany.neo4jDataDir}"/>
    <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="config" class="com.mycompany.Neo4jServerConfig">
    <constructor-arg> 
        <map>
            <entry key="org.neo4j.server.webserver.address" value="0.0.0.0"/>
        </map>
    </constructor-arg>     
</bean>

<bean id="serverWrapper" class="org.neo4j.server.WrappingNeoServerBootstrapper" init-method="start" destroy-method="stop">
    <constructor-arg index="0" ref="graphDatabaseService"/>
    <constructor-arg index="1" ref="config"/>
</bean>

这是配置类:

public class Neo4jServerConfig implements Configurator {

    private Configuration config;

    public Ne4jServerConfig(Map<String, String> config) {
        this.config = new MapConfiguration(config);
    }

    @Override
    public Configuration configuration() {
        return config; 
    }

    @Override
    public Map<String, String> getDatabaseTuningProperties() {
        return null;
    }

    @Override
    public Set<ThirdPartyJaxRsPackage> getThirdpartyJaxRsClasses() {
        return new HashSet<>();
    }
}