Невозможно записать в файл свойств в Spring - PullRequest
0 голосов
/ 08 февраля 2019

У меня есть следующий класс Spring, который пытается записать новое значение свойства в файл свойств:

@Service
public class Operations {

    public void changeProperties() {
        Properties prop = new Properties();
        OutputStream output = null;

        try {
            output = new FileOutputStream("rest-endpoint.properties");
            prop.setProperty("meta.db.device.url", "localhost");
            prop.store(output, null);
        } catch (IOException io) {
            io.printStackTrace();
        } finally {
            if (output != null) {
                try {
                    output.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
}

Я также пробовал этот код:

try {
    Properties props = new Properties();
    props.setProperty("Prop1", "toto");
    File f = new File("rest-endpoint.properties");
    OutputStream out = new FileOutputStream( f );
    DefaultPropertiesPersister p = new DefaultPropertiesPersister();
    p.store(props, out, "Header Comment");
} catch (Exception e ) {
    e.printStackTrace();
}

и мой *Файл 1007 *:

meta.db.device.url=http://edgex-core-metadata:48081/api/v1/device
meta.db.devicemanager.url=http://edgex-core-metadata:48081/api/v1/devicemanager
meta.db.ping.url=http://edgex-core-metadata:48081/api/v1/ping

Однако, когда я выполняю код, в файле свойств ничего не меняется.Есть идеи, что может пойти не так?

...