File tree Expand file tree Collapse file tree 8 files changed +15
-50
lines changed
java/com/didispace/chapter15
test/java/com/didispace/chapter15 Expand file tree Collapse file tree 8 files changed +15
-50
lines changed Original file line number Diff line number Diff line change 25
25
### 配置文件
26
26
27
27
- [ Spring Boot 2.x基础教程:配置文件详解] ( http://blog.didispace.com/spring-boot-learning-21-1-3/ )
28
+ - [ Spring Boot 2.x基础教程:配置元数据的应用 ] ( http://blog.didispace.com/spring-boot-learning-24-1-6/ )
28
29
- [ Spring Boot 2.x基础教程:2.4版本前后的多环境配置变化] ( http://blog.didispace.com/spring-boot-learning-24-1-4/ )
29
30
- [ Spring Boot 2.x基础教程:2.4版本前后的分组配置变化] ( http://blog.didispace.com/spring-boot-learning-24-1-5/ )
30
- - [ Spring Boot 2.x基础教程:配置元数据的应用 ] ( http://blog.didispace.com/spring-boot-learning-24 -1-6 / )
31
+ - [ Spring Boot 2.x基础教程:加密配置中的敏感信息 ] ( http://blog.didispace.com/spring-boot-learning-2 -1-5 / )
31
32
32
33
### API开发
33
34
Original file line number Diff line number Diff line change 26
26
### 配置文件
27
27
28
28
- [ Spring Boot 2.x基础教程:配置文件详解] ( http://blog.didispace.com/spring-boot-learning-21-1-3/ )
29
+ - [ Spring Boot 2.x基础教程:配置元数据的应用 ] ( http://blog.didispace.com/spring-boot-learning-24-1-6/ )
29
30
- [ Spring Boot 2.x基础教程:2.4版本前后的多环境配置变化] ( http://blog.didispace.com/spring-boot-learning-24-1-4/ )
30
31
- [ Spring Boot 2.x基础教程:2.4版本前后的分组配置变化] ( http://blog.didispace.com/spring-boot-learning-24-1-5/ )
31
- - [ Spring Boot 2.x基础教程:配置元数据的应用 ] ( http://blog.didispace.com/spring-boot-learning-24 -1-6 / )
32
+ - [ Spring Boot 2.x基础教程:加密配置中的敏感信息 ] ( http://blog.didispace.com/spring-boot-learning-2 -1-5 / )
32
33
33
34
### API开发
34
35
Original file line number Diff line number Diff line change 11
11
<groupId >com.didispace</groupId >
12
12
<artifactId >chapter1-5</artifactId >
13
13
<version >0.0.1-SNAPSHOT</version >
14
- <description >敏感配置信息的加密 </description >
14
+ <description >加密配置中的敏感信息 </description >
15
15
16
16
<properties >
17
17
<java .version>1.8</java .version>
Original file line number Diff line number Diff line change 1
1
package com .didispace .chapter15 ;
2
2
3
- import com .ulisesbocchio .jasyptspringboot .annotation .EnableEncryptableProperties ;
4
- import org .springframework .beans .factory .annotation .Autowired ;
5
3
import org .springframework .boot .SpringApplication ;
6
4
import org .springframework .boot .autoconfigure .SpringBootApplication ;
7
- import org .springframework .web .bind .annotation .GetMapping ;
8
- import org .springframework .web .bind .annotation .RestController ;
9
5
10
6
@ SpringBootApplication
11
- @ EnableEncryptableProperties
12
7
public class Chapter15Application {
13
8
14
9
public static void main (String [] args ) {
15
10
SpringApplication .run (Chapter15Application .class , args );
16
11
}
17
12
18
- @ RestController
19
- static class HelloController {
20
-
21
- @ Autowired
22
- private JasyptExample jasyptExample ;
23
-
24
- @ GetMapping ("/hello" )
25
- public String hello () {
26
- return "Hello World, " + jasyptExample .getFrom2 ();
27
- }
28
-
29
- }
30
-
31
13
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
2
- com.didispace.from1 =didi
3
- com.didispace.from2 =ENC(1I1oWHryzOJt+Gm81xnGnOUbBUpEBEFYES/NprA/q6ec3jBkU1xlBZWsHCaj71ds)
2
+ datasource.password =ENC(/AL9nJENCYCh9Pfzdf2xLPsqOZ6HwNgQ3AnMybFAMeOM5GphZlOK6PxzozwtCm+Q)
4
3
5
4
jasypt.encryptor.password =didispace
6
5
7
- # [INFO] Encryptor config not found for property jasypt.encryptor.salt-generator-classname, using default value: org.jasypt.salt.RandomSaltGenerator
8
- # [INFO] Encryptor config not found for property jasypt.encryptor.iv-generator-classname, using default value: org.jasypt.iv.RandomIvGenerator
9
-
10
6
# mvn jasypt:encrypt -Djasypt.encryptor.password=didispace
11
- # mvn jasypt:decrypt -Djasypt.encryptor.password=didispace
7
+ # mvn jasypt:decrypt -Djasypt.encryptor.password=didispace
8
+
9
+ # jasypt.encryptor.property.prefix=ENC(
10
+ # jasypt.encryptor.property.suffix=)
Original file line number Diff line number Diff line change 3
3
import lombok .extern .slf4j .Slf4j ;
4
4
import org .junit .jupiter .api .Test ;
5
5
import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .beans .factory .annotation .Value ;
6
7
import org .springframework .boot .test .context .SpringBootTest ;
7
8
8
9
@ Slf4j
9
10
@ SpringBootTest
10
11
public class PropertiesTest {
11
12
12
- @ Autowired
13
- private JasyptExample jasyptExample ;
13
+ @ Value ( "${datasource.password:}" )
14
+ private String password ;
14
15
15
16
@ Test
16
17
public void test () {
17
- log .info ("from1 : {}" , jasyptExample .getFrom1 ());
18
- log .info ("from2 : {}" , jasyptExample .getFrom2 ());
18
+ log .info ("datasource.password : {}" , password );
19
19
}
20
20
21
21
}
Original file line number Diff line number Diff line change 16
16
<module >chapter1-2</module > <!-- 2.4版本前后的多环境配置与配置激活 -->
17
17
<module >chapter1-3</module > <!-- 2.4版本前后的配置分组配置 -->
18
18
<module >chapter1-4</module > <!-- 配置元数据的应用 -->
19
- <module >chapter1-5</module > <!-- 敏感配置信息的加密 -->
19
+ <module >chapter1-5</module > <!-- 加密配置文件中的敏感信息 -->
20
20
21
21
<!-- API开发-->
22
22
<module >chapter2-1</module > <!-- 构建RESTful API与单元测试 -->
You can’t perform that action at this time.
0 commit comments