Java Spring将属性从FTP服务器加载到上下文中

Java Spring将属性从FTP服务器加载到上下文中,java,spring,properties,ftp,applicationcontext,Java,Spring,Properties,Ftp,Applicationcontext,我有一个应用程序,而不是带有属性文件的webapplication。我需要从服务器上的一个文件中加载几个属性到它的上下文中,但我不能,因为我不知道如何加载,或者我误解了这一点。 我有一个代表SFtp的类,我可以连接到服务器下载和检索文件 我如何在我的上下文中包含并使用所有这些属性作为配置属性,或者如何修改上下文的XML以包含该文件 创建一个Bean以这样的方式使用读取属性是一个更好的主意: public class ServerProperties{ public static ServerP

我有一个应用程序,而不是带有属性文件的webapplication。我需要从服务器上的一个文件中加载几个属性到它的上下文中,但我不能,因为我不知道如何加载,或者我误解了这一点。 我有一个代表SFtp的类,我可以连接到服务器下载和检索文件

我如何在我的上下文中包含并使用所有这些属性作为配置属性,或者如何修改上下文的XML以包含该文件

创建一个Bean以这样的方式使用读取属性是一个更好的主意:

public class ServerProperties{
 public static ServerPropertiesgetInstance() {
        if (ServerProperties.instance == null) {
            try {
                final InputStream file = ServerProperties.getFileFromServer();

            ServerProperties.instance = new CommonProperties();
            ServerProperties.instance.environmentsProperties.load(file);
        } catch (final IOException e) {

        }
    }
    return ServerProperties.instance;
}
public String getterProp1() { return this.environmentsProperties.get("Prop1"); }
public String getterProp2()  return this.environmentsProperties.get("Prop2");}
[...]
public String getterPropN() { return this.environmentsProperties.get("PropN");}
您应该使用带有location或locations属性的。它们接受哪些可以使用FTP服务器位置

大概是这样的:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>ftp://some_host/folder/file.properties</value>
        </list>
    </property>
</bean>