毕设-01-SpringBoot数据库密码加密-hikari,不使用druid

不会现在还有人不加密吧?虽然我之前也懒得加密。。。

环境:Spring Boot ::        (v2.1.6.RELEASE) ;mybatis

1、maven导包:

        
            com.github.ulisesbocchio
            jasypt-spring-boot-starter
            2.1.1
        

2、application.properties文件加

jasypt.encryptor.password=foo

3、单元测试运行下:

@RunWith(SpringRunner.class)
@SpringBootTest
public class HikariTest {

    @Autowired
    private StringEncryptor stringEncryptor;

    @Test
    public void testEnvironmentProperties() {
        System.out.println(stringEncryptor.encrypt("你的数据库密码"));
    }

}

然后会得到数据库密码加密后的字符串:gwMk8PXkrJTA4K*****************

4、修改application.properties

原:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=明文
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&useUnicode=true&serverTimezone=GMT%2B8

修改后:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&useUnicode=true&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=ENC(gwMk8PXkrJTA4K*****************)

5、数据库连接池

spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.maximum-pool-size=30
spring.datasource.hikari.idle-timeout=60000
spring.datasource.hikari.pool-name=DatebookHikariCP
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 'x' FROM DUAL
spring.datasource.type=com.zaxxer.hikari.HikariDataSource

到这加密就完成啦 

随便截一张图

你可能感兴趣的:(毕业设计,数据库,mybatis)