over 8 years ago
有些設定檔比如說像是加解密金鑰會需要在載入設定檔的時候就做好處理
透過PropertyPlaceholderConfigurer來達成
先新增要處理設定檔的程式,底下是初始化加密程式的範例
import java.util.Properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
public class RSASecurityPropertyConfigurer extends PropertyPlaceholderConfigurer{
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException {
String pubkeybase64str = props.getProperty("publicecnoded");
String privkeybase64str = props.getProperty("privateecnoded");
com.mitake.utils.RSAUtils.setNewRSAKey(pubkeybase64str, privkeybase64str);
System.out.println("RSA金鑰載入完成");
}
}
然後要在Spring設定檔標註你定義的處理程序
<bean id="propertyConfigurer" class="com.secom.mobile.component.RSASecurityPropertyConfigurer">
<property name="locations">
<list>
<!-- 如果你是放在class資料夾底下用此設定 -->
<value>classpath:security.properties</value>
</list>
</property>
</bean>