【发布时间】:2016-02-01 07:36:11
【问题描述】:
我有一个问题,正在寻找在 java 运行时更改系统属性的示例。换句话说,我有一个独立的库,它将加载System.setProperty("javax.net.ssl.trustStore", trustStorePath),其中 trustStorePath 的值将根据条件而变化。如果条件发生变化,那么我需要更改 trustStorePath 的值并需要设置系统属性。
但故事是当我第一次设置该值时,它会存储该值并使用它,即使我更改了 trustStorePath 的值并再次设置系统属性。变化没有反映出来。
那么,我该怎么做。下面是相同的示例代码 sn-p。
if (getFile(keyStorePath).exists() && isChanged ) {
System.setProperty("javax.net.ssl.keyStore", keyStorePath);
System.setProperty("javax.net.ssl.keyStoreType", "JKS");
System.setProperty("javax.net.ssl.keyStorePassword", Pwd);
}else if (getFile(testMerchantKeyStorePath).exists() ) {
System.setProperty("javax.net.ssl.keyStore", testMerchantKeyStorePath);
System.setProperty("javax.net.ssl.keyStoreType", "JKS");
System.setProperty("javax.net.ssl.keyStorePassword",Pwd);
}
【问题讨论】:
标签: java runtime keystore truststore system-properties