title: PropertyPlaceholderConfigurer and PropertySourcesPlaceholderConfigurer run differently
body: <p>I used the DES algorithm to encrypt the username and password in jdbc.properties, and used the PropertyPlaceholderConfigurer for decryption, but found that this class has been deprecated. So use PropertySourcesPlaceholderConfigurer to replace.</p>
  
  <p>The bean has been added in spring-dao.xml, and the class is filled with the class containing the decryption method inherited from PropertySourcesPlaceholderConfigurer.</p>
  
  <p><strong>I put a breakpoint on the first line of the decryption method</strong>, and then started tomcat to send an access request. At this point, the backend should call the database. <strong>But if the decryption class inherits from PropertySourcesPlaceholderConfigurer, the first line of the decryption method will not be executed. If the decryption class inherits from PropertyPlaceholderConfigurer, the first line of the decryption method is executed.</strong> I don't know why this is the case, should I use the deprecated PropertyPlaceholderConfigurer?</p>
  
  <p><strong>spring.version: 5.2.0.RELEASE</strong></p>
  
  <p>Part of spring-dao.xml</p>
  
  <pre><code>&lt;!--&lt;context:property-placeholder location="classpath:jdbc.properties" /&gt;--&gt;
  &lt;bean class="com.imooc.o2o.util.EncryptPropertySourcesPlaceholderConfigurer"&gt;
      &lt;property name="locations"&gt;
          &lt;list&gt;
              &lt;value&gt;classpath:jdbc.properties&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="fileEncoding" value="UTF-8" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>EncryptPropertySourcesPlaceholderConfigurer.java (My decryption algorithm class)</p>
  
  <pre><code>package com.imooc.o2o.util;
  
  import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
  import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
  
  public class EncryptPropertySourcesPlaceholderConfigurer extends PropertySourcesPlaceholderConfigurer {
      // Fields to be encrypted
      private String[] encryptPropNames = {"jdbc.username", "jdbc.password"};
  
      /**
       * Transform key attributes
       * @param propertyName
       * @param propertyValue
       * @return
       */
      @Override
      protected String convertProperty(String propertyName, String propertyValue) {
          if (isEncryptProp(propertyName)) {
              // Decrypting encrypted fields
              String decryptValue = DESUtil.getDecryptString(propertyValue);
              return decryptValue;
          } else {
              return propertyValue;
          }
      }
  
      /**
       * Whether the attribute is encrypted
       * @param propertyName
       * @return
       */
      private boolean isEncryptProp(String propertyName) {
          // If it is equal to the field to be encrypted, it has been encrypted
          for (String encryptPropertyName : encryptPropNames) {
              if (encryptPropertyName.equals(propertyName)) {
                  return true;
              }
          }
          return false;
      }
  }
  </code></pre>
  
  <p>DESUtil.java</p>
  
  <pre><code>package com.imooc.o2o.util;
  
  import javax.crypto.Cipher;
  import javax.crypto.KeyGenerator;
  import java.security.Key;
  import java.security.SecureRandom;
  import java.util.Base64;
  
  /**
   * DES is a symmetric encryption algorithm. The so-called symmetric encryption algorithm is an algorithm that uses the same key for encryption and decryption.
   */
  public class DESUtil {
      private static Key key;
      private static String KEY_STR = "myKey";
      private static String CHAR_SET_NAME = "UTF-8";
      private static String ALGORITHM = "DES";
  
      static {
          try {
              // Generate DES Algorithm Object
              KeyGenerator generator = KeyGenerator.getInstance(ALGORITHM);
              // Apply SHA1 security policy
              SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
              // Setting the key seed
              secureRandom.setSeed(KEY_STR.getBytes());
              // Initialize SHA1-based algorithm objects
              generator.init(secureRandom);
              // Generate a key object
              key = generator.generateKey();
              generator = null;
          } catch (Exception e) {
              throw new RuntimeException(e);
          }
      }
  
      // Get encrypted information
      public static String getEncryptString(String str) {
          // Based on BASE64 encoding, receive byte [] and convert to String
          Base64.Encoder encoder = Base64.getEncoder();
          try {
              // Encoded as UTF-8
              byte[] bytes = str.getBytes(CHAR_SET_NAME);
              // Get the encrypted object
              Cipher cipher = Cipher.getInstance(ALGORITHM);
              // Initialize password information
              cipher.init(Cipher.ENCRYPT_MODE, key);
              // encryption
              byte[] doFinal = cipher.doFinal(bytes);
              // byte[] to encode a good String and return
              return encoder.encodeToString(doFinal);
          } catch (Exception e) {
              throw new RuntimeException();
          }
      }
  
      // Get the decrypted information
      public static String getDecryptString(String str) {
          // Based on BASE64 encoding, receive byte[] and convert to String
          Base64.Decoder decoder = Base64.getDecoder();
          try {
              // Decode string into byte []
              byte[] bytes = decoder.decode(str);
              // Get the decrypted object
              Cipher cipher = Cipher.getInstance(ALGORITHM);
              // Initialize decryption information
              cipher.init(Cipher.DECRYPT_MODE, key);
              byte[] doFinal = cipher.doFinal(bytes);
              // Returns the decrypted information
              return new String(doFinal, CHAR_SET_NAME);
          } catch (Exception e) {
              throw new RuntimeException();
          }
      }
  
      /**
       * Get the string to be encrypted
       * @param args
       */
      public static void main(String[] args) {
          System.out.println(getEncryptString(""));
          System.out.println(getEncryptString(""));
      }
  }
  </code></pre>