spring.xml中的加密jdbc信息进行解密

  • extends PropertyPlaceholderConfigurer
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
	
	public static Logger log=LoggerFactory.getLogger(EncryptPropertyPlaceholderConfigurer.class);

	//设置需要解密的属性
	private String[] encryptPropNames= {"jdbc.username","jdbc.password","jdbc.url"};
	@Override
	protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
			throws BeansException {
		if(null!=encryptPropNames) {
			try {
				for(String propName : encryptPropNames) {
					if(props.get(propName)!=null) {
						props.setProperty(propName,AESUtil.decrypt(props.get(propName).toString()) );
					}
				}
			} catch (RuntimeException | UnsupportedEncodingException e) {
				log.info("执行失败");
			}
			
		}
		super.processProperties(beanFactoryToProcess,props);
	}
	

}

  • spring.xml

	
		
			
				classpath:properties/sys_config.properties
			
		
	

spring.xml中的加密jdbc信息进行解密_第1张图片

你可能感兴趣的:(spring.xml中的加密jdbc信息进行解密)