對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