对druid数据源密码进行加密的方法
1.首先,在druid中新建一个数据源配置类;
@Configuration
public class DruidConfig {
@Value("${spring.datasource.publicKey}")
private String publicKey;
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DruidDataSource dataSource() throws SQLException {
DruidDataSource druidDataSource = new DruidDataSource();
druidDataSource.setFilters("config");
druidDataSource.setConnectionProperties("config.decrypt=true;config.decrypt.key=" + publicKey);
return druidDataSource;
}
}
2.druid数据源配置类新建好后,在命令行中执行以下命令即可对数据源密码进行加密;
java -cp druid-1.0.16.jar com.alibaba.druid.filter.config.ConfigTools you_password