Administrator
2023-04-19 40ec16bbb7c9d23df625aa31ae42ac36e901749d
提交 | 用户 | 时间
58d006 1 package com.mandi.common;
A 2
3 import java.util.Properties;
4
5 import org.springframework.beans.BeansException;
6 import org.springframework.beans.factory.BeanInitializationException;
7 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
8 import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
9
10 public class PropertyConfig extends PropertyPlaceholderConfigurer{
11     private static final String key = ConstantVar.JDBC_DESC_KEY;
12     protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)throws BeansException {
13         try {
14             String username = props.getProperty(ConstantVar.JDBC_DATASOURCE_USERNAME_KEY);
15             if (username != null) {
16                 props.setProperty(ConstantVar.JDBC_DATASOURCE_USERNAME_KEY, BasicMethod.decryptAES(username, key));
17             }
18             String password = props.getProperty(ConstantVar.JDBC_DATASOURCE_PASSWORD_KEY);
19             if (password != null) {
20                 props.setProperty(ConstantVar.JDBC_DATASOURCE_PASSWORD_KEY, BasicMethod.decryptAES(password, key));
21             }
22             
23             String url = props.getProperty(ConstantVar.JDBC_DATASOURCE_URL_KEY);
24             if (url != null) {
25                 props.setProperty(ConstantVar.JDBC_DATASOURCE_URL_KEY, BasicMethod.decryptAES(url, key));
26             }
27             
28             String driverClassName = props.getProperty(ConstantVar.JDBC_DATASOURCE_DRIVERCLASSNAME_KEY);
29             if(driverClassName != null){
30                 props.setProperty(ConstantVar.JDBC_DATASOURCE_DRIVERCLASSNAME_KEY, BasicMethod.decryptAES(driverClassName, key));
31             }
32             super.processProperties(beanFactory, props);
33         } catch (Exception e) {
34             e.printStackTrace();
35             throw new BeanInitializationException(e.getMessage());
36         }
37      }
38 }