Neo4j服务器插件配置

Neo4j服务器插件配置,neo4j,Neo4j,我正在构建一个Neo4J服务器插件。我希望有一些配置值可以在neo4j.properties或neo4j-server.properties中手动设置,然后插件可以读取并利用这些值。如何从服务器插件访问配置值 澄清: 我真的很希望能在Neo4J的未来版本中使用,因此最好使用公共API的一部分,并且不推荐使用。使用Neo4J的内部依赖机制,您可以访问配置的实例。此类允许您访问配置 以以下未经测试的代码段为指导: ... import org.neo4j.kernel.configuration.C

我正在构建一个Neo4J服务器插件。我希望有一些配置值可以在neo4j.properties或neo4j-server.properties中手动设置,然后插件可以读取并利用这些值。如何从服务器插件访问配置值

澄清:
我真的很希望能在Neo4J的未来版本中使用,因此最好使用公共API的一部分,并且不推荐使用。

使用Neo4J的内部依赖机制,您可以访问
配置的实例。此类允许您访问配置

以以下未经测试的代码段为指导:

...
import org.neo4j.kernel.configuration.Config
...

@Description( "An extension to the Neo4j Server accessing config" )
public class ConfigAwarePlugin extends ServerPlugin
{
    @Name( "config" )
    @Description( "Do stuff with config" )
    @PluginTarget( GraphDatabaseService.class )
    public void sample( @Source GraphDatabaseService graphDb ) {
        Config config = ((GraphDatabaseAPI)graphDb).getDependencyResolver().resolveDependency(Config.class);

        // do stuff with config
    }
}

我使用
属性

    Properties props = new Properties();
    try
    {
        FileInputStream in = new FileInputStream("./conf/neo4j.properties");
        props.load(in);
    }
    catch (FileNotFoundException e)
    {
        try
        {
            FileInputStream in = new FileInputStream("./neo4j.properties");
            props.load(in);
        }
        catch (FileNotFoundException e2)
        {
            logger.warn(e2.getMessage());
        }
        catch (IOException e2)
        {
            logger.warn(e2.getMessage());
        }
    }
    catch (IOException e)
    {
        logger.warn(e.getMessage());
    }
    String myPropertyString = props.getProperty("myProperty");
    if (myPropertyString != null)
    {
        myProperty = Integer.parseInt(myPropertyString);
    }
    else
    {
        myProperty = 100;
    }
neo4j.properties
中,我有:

...    
# Enable shell server so that remote clients can connect via Neo4j shell.
#remote_shell_enabled=true
# Specify custom shell port (default is 1337).
#remote_shell_port=1234

myProperty=100

谢谢这确实有效,但我希望将来能得到支持。1) GraphDatabaseAPI接口已被弃用,其消息为“这将在下一个主要版本中移动到内部包。”2)getDependencyResolver方法有一条消息“此方法的使用通常表示架构错误”。3)Config.getParams方法的代码中有一个TODO“摆脱它,让我们拥有更精细的内部存储(例如,可以保留具有属性的元数据的存储)。“我担心这种方法的寿命。谢谢。我也有您在代码中部分解决的问题,即服务器从何处启动,并尝试从相对路径加载neo4j.properties。