Apache WS44J无法正确获取环境变量

时间:2018-07-17 17:35:44

标签: java properties environment-variables wss4j

我的Spring Boot应用程序中有一个使用环境变量的属性文件

org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=${env:keyStorePassword}
org.apache.ws.security.crypto.merlin.keystore.alias=${env:keyAlias}
org.apache.ws.security.crypto.merlin.keystore.file=${env:keyStoreFilePath}

但是,它表示找不到文件,而同时提供了文件的路径。因此,它正在正确地从环境文件中提取值。我还复制了文字值,而不是环境变量,并将其放在属性文件中,并且效果很好。为什么当我退出环境时却说找不到文件?

这是错误日志

17:06:12.537 [http-nio-8080-exec-1] DEBUG org.apache.ws.security.util.Loader - Trying to find [<file>] using org.springframework.boot.loader.LaunchedURLClassLoader@38af3868 class loader.
17:06:12.542 [http-nio-8080-exec-1] DEBUG org.apache.ws.security.util.Loader - Trying to find [<file>] using org.springframework.boot.loader.LaunchedURLClassLoader@38af3868 class loader.
17:06:12.559 [http-nio-8080-exec-1] DEBUG org.apache.ws.security.util.Loader - Trying to find [<file>] using ClassLoader.getSystemResource().
17:06:12.568 [http-nio-8080-exec-1] DEBUG org.apache.ws.security.components.crypto.Merlin - <file> (No such file or directory)
java.io.FileNotFoundException: ${env:keyStoreFilePath} (No such file or directory)

该标记与环境变量中的文件路径完全相同。

感谢您提供的任何帮助。

1 个答案:

答案 0 :(得分:1)

我解决了此错误,原因是我仍然不完全了解,该环境变量以某种不同的格式存储。因此,我改为使用一些好的旧Java将变量注入到属性文件中。

try {
    PropertiesConfiguration props = new PropertiesConfiguration(System.getenv("SIGNATURE_PROPS_FILE"));
    props.setProperty("org.apache.ws.security.crypto.merlin.keystore.password", System.getenv("KEY_STORE_PASSWORD"));
    props.setProperty("org.apache.ws.security.crypto.merlin.keystore.alias", System.getenv("KEY_ALIAS"));
    props.setProperty("org.apache.ws.security.crypto.merlin.keystore.file", System.getenv("KEY_STORE_FILE"));
    props.save();
    logger.debug("** signature.properties updated Successfully!! **");
} catch (ConfigurationException e) {
    logger.error(e.getMessage());
}
相关问题