File tree Expand file tree Collapse file tree 6 files changed +81
-18
lines changed
java/com/didispace/chapter15
test/java/com/didispace/chapter15 Expand file tree Collapse file tree 6 files changed +81
-18
lines changed Original file line number Diff line number Diff line change 23
23
<artifactId >spring-boot-starter-web</artifactId >
24
24
</dependency >
25
25
26
+ <dependency >
27
+ <groupId >com.github.ulisesbocchio</groupId >
28
+ <artifactId >jasypt-spring-boot-starter</artifactId >
29
+ <version >3.0.3</version >
30
+ </dependency >
31
+
26
32
<dependency >
27
33
<groupId >org.projectlombok</groupId >
28
34
<artifactId >lombok</artifactId >
41
47
<groupId >org.springframework.boot</groupId >
42
48
<artifactId >spring-boot-maven-plugin</artifactId >
43
49
</plugin >
50
+
51
+ <plugin >
52
+ <groupId >com.github.ulisesbocchio</groupId >
53
+ <artifactId >jasypt-maven-plugin</artifactId >
54
+ <version >3.0.3</version >
55
+ </plugin >
44
56
</plugins >
45
57
</build >
46
58
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 ;
3
5
import org .springframework .boot .SpringApplication ;
4
6
import org .springframework .boot .autoconfigure .SpringBootApplication ;
7
+ import org .springframework .web .bind .annotation .GetMapping ;
8
+ import org .springframework .web .bind .annotation .RestController ;
5
9
6
10
@ SpringBootApplication
11
+ @ EnableEncryptableProperties
7
12
public class Chapter15Application {
8
13
9
- public static void main (String [] args ) {
10
- SpringApplication .run (Chapter15Application .class , args );
11
- }
14
+ public static void main (String [] args ) {
15
+ SpringApplication .run (Chapter15Application .class , args );
16
+ }
17
+
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
+ }
12
30
13
31
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ package com .didispace .chapter15 ;
2
+
3
+ import lombok .Data ;
4
+ import lombok .extern .slf4j .Slf4j ;
5
+ import org .springframework .beans .factory .annotation .Value ;
6
+ import org .springframework .stereotype .Component ;
7
+
8
+ @ Slf4j
9
+ @ Data
10
+ @ Component
11
+ public class JasyptExample {
12
+
13
+ @ Value ("${com.didispace.from1:}" )
14
+ private String from1 ;
15
+ @ Value ("${com.didispace.from2:}" )
16
+ private String from2 ;
17
+
18
+ }
Original file line number Diff line number Diff line change 1
1
2
- com.didispace.from =didi
2
+ com.didispace.from1 =didi
3
+ com.didispace.from2 =ENC(1I1oWHryzOJt+Gm81xnGnOUbBUpEBEFYES/NprA/q6ec3jBkU1xlBZWsHCaj71ds)
3
4
5
+ jasypt.encryptor.password =didispace
6
+
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
+ # mvn jasypt:encrypt -Djasypt.encryptor.password=didispace
11
+ # mvn jasypt:decrypt -Djasypt.encryptor.password=didispace
Original file line number Diff line number Diff line change
1
+ package com .didispace .chapter15 ;
2
+
3
+ import lombok .extern .slf4j .Slf4j ;
4
+ import org .junit .jupiter .api .Test ;
5
+ import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .boot .test .context .SpringBootTest ;
7
+
8
+ @ Slf4j
9
+ @ SpringBootTest
10
+ public class PropertiesTest {
11
+
12
+ @ Autowired
13
+ private JasyptExample jasyptExample ;
14
+
15
+ @ Test
16
+ public void test () {
17
+ log .info ("from1 : {}" , jasyptExample .getFrom1 ());
18
+ log .info ("from2 : {}" , jasyptExample .getFrom2 ());
19
+ }
20
+
21
+ }
You can’t perform that action at this time.
0 commit comments