春天没有阅读资源属性

时间:2013-11-19 19:17:47

标签: java spring spring-mvc

我有bean试图加载JKS文件。

protected final Log log = LogFactory.getLog(this.getClass());

private KeyStore keyStore;
private char[] keyStorePassword;
private KeyStore trustStore;
/**
 * @param keyStore the keyStore to set
 */
public void setKeyStore(Resource keyStore) {
    this.keyStore = getKeystoreFromResource(keyStore, keyStorePassword);
}
/**
 * @param trustStore the trustStore to set
 */
public void setTrustStore(Resource trustStore) {
    this.trustStore = getKeystoreFromResource(trustStore, keyStorePassword);
}
/**
 * @param keyStorePassword the keyStorePassword to set
 */
public void setKeyStorePassword(char[] keyStorePassword) {
    this.keyStorePassword = keyStorePassword;
}
/**
 * 
 * @param resource
 * @param password
 * @return
 */
protected static KeyStore getKeystoreFromResource(Resource resource, char[] password) {
    try {
        KeyStore k = KeyStore.getInstance(KeyStore.getDefaultType());
        k.load(resource.getInputStream(), password);
        return k;
    } catch (KeyStoreException e) {
        throw new IllegalArgumentException("failed to load keystore from " + resource.getDescription(), e);
    } catch (CertificateException e) {
        throw new IllegalArgumentException("failed to load keystore from " + resource.getDescription(), e);
    } catch (IOException e) {
        throw new IllegalArgumentException("failed to load keystore from " + resource.getDescription(), e);
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalArgumentException("failed to load keystore from " + resource.getDescription(), e);
    }

}

我已将资源值设置为

    <property name="keyStore" value="${keyStore}"/>

in properties

   keyStore=/home/users/test.jks

但是当我尝试调用相同的文件时,我收到了一个未找到文件的异常。

我不确定我是否错误地设置了资源值。

亚当。

0 个答案:

没有答案