spring change placeholder property value

need:

    Like database passwords, they generally cannot be expressed in plaintext in a properties file. Then you need to encrypt the password and configure the encrypted ciphertext in the configuration file. When running, load the property file and then restore the ciphertext to plaintext, and provide it to the jdbc driver as a connection database parameter.

 

accomplish:

java:

public class DecryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
	@Override
	protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
			throws BeansException {

		Properties p = decodeProperties(props);//Decrypt properties here
		super.processProperties(beanFactoryToProcess, p);
	}
}

 xml placement:

  	<!-- original placeholder attribute
	<bean id="webframe.datasource.config" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		-->
	<bean id="webframe.datasource.config" class="com.skyon.webframe.config.DecryptPropertyPlaceholderConfigurer">	
		<property name="order" value="1" />
    	<property name="ignoreUnresolvablePlaceholders" value="true" />
    	<property name="properties" ref="mm" />
        <!-- mm uses ciphertext for the attribute here-->
	</bean>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326316832&siteId=291194637