0

I have an application (not webapplication) with its property file. And I need to load into its context several properties from a file on a server, but I couldn't (because I don't know how or I have misunderstood something about that). I have a class which represent a SFtp and I can connect to the server to download and retrieve the file.

How can I include and use all of those properties on my context as a configuration properties or maybe how can modify the XML of context to include that file?

Is a better idea to create a Bean to use the read properties in this way:

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");}
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Elorry
  • 33
  • 7

1 Answers1

0

You should use a PropertyPlaceHolderConfigurer with the location or locations property. They accept Resources which can use FTP server locations.

Something like this:

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