EncryptablePropertyPlaceholderConfigurer.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package com.uas.credit.config;
  2. import com.uas.credit.support.Des;
  3. import org.springframework.beans.BeansException;
  4. import org.springframework.beans.factory.BeanInitializationException;
  5. import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
  6. import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
  7. import java.util.Properties;
  8. /**
  9. * 将加密的 userId password 进行解密
  10. * @author liuam
  11. * @since 2018/6/25 0025 下午 17:26
  12. */
  13. public class EncryptablePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
  14. private static final String key = "10101010";
  15. protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
  16. throws BeansException {
  17. try {
  18. Des des = new Des();
  19. String userId = props.getProperty("pyconfig.userId");
  20. if (userId != null) {
  21. props.setProperty("pyconfig.userId", userId);
  22. }
  23. String password = props.getProperty("pyconfig.password");
  24. if (password != null) {
  25. props.setProperty("pyconfig.password", password);
  26. }
  27. // 自定义完成后调用父类方法
  28. super.processProperties(beanFactory, props);
  29. } catch (Exception e) {
  30. e.printStackTrace();
  31. throw new BeanInitializationException(e.getMessage());
  32. }
  33. }
  34. }