1. Introduce Maven dependencies

<dependencies>
	...
	<dependency>
		<groupId>com.github.ulisesbocchio</groupId>
		<artifactId>jasypt-spring-boot-starter</artifactId>
		<version>${jasypt.version}</version>
	</dependency>
	...
<dependencies>
Copy the code

2, application-dev.yml

Jasypt: encryptor: Password: Lynseries #Copy the code

3. Obtain the encrypted value

Using the @ SpringBootTest

package com.lynseries.test import lombok.extern.slf4j.Slf4j; import org.jasypt.encryption.StringEncryptor; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; /** * @author lynseries * @date */ @SpringBootTest(classes = TestApplication.class) public class MyApplicationTest { @Autowired private StringEncryptor stringEncryptor; @Test public void testJasypt(){ String enpassword=stringEncryptor.encrypt("lynseries"); System.out.println("encode password:" + enpassword); System.out.println("decode password:" + stringEncryptor.decrypt(enpassword)); }} Result: encode password:t4dRt2z++RAMMG9u9ObUIQp3mf8FTi0v decode password:lynseriesCopy the code

4. Use it in the configuration file

spring:
  datasource:
    password: ENC(t4dRt2z++RAMMG9u9ObUIQp3mf8FTi0v)
Copy the code