Skip to content

Commit e440510

Browse files
committed
update
1 parent e12aa4f commit e440510

File tree

6 files changed

+81
-18
lines changed

6 files changed

+81
-18
lines changed

2.x/chapter1-5/pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
<artifactId>spring-boot-starter-web</artifactId>
2424
</dependency>
2525

26+
<dependency>
27+
<groupId>com.github.ulisesbocchio</groupId>
28+
<artifactId>jasypt-spring-boot-starter</artifactId>
29+
<version>3.0.3</version>
30+
</dependency>
31+
2632
<dependency>
2733
<groupId>org.projectlombok</groupId>
2834
<artifactId>lombok</artifactId>
@@ -41,6 +47,12 @@
4147
<groupId>org.springframework.boot</groupId>
4248
<artifactId>spring-boot-maven-plugin</artifactId>
4349
</plugin>
50+
51+
<plugin>
52+
<groupId>com.github.ulisesbocchio</groupId>
53+
<artifactId>jasypt-maven-plugin</artifactId>
54+
<version>3.0.3</version>
55+
</plugin>
4456
</plugins>
4557
</build>
4658

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
package com.didispace.chapter15;
22

3+
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
4+
import org.springframework.beans.factory.annotation.Autowired;
35
import org.springframework.boot.SpringApplication;
46
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.web.bind.annotation.GetMapping;
8+
import org.springframework.web.bind.annotation.RestController;
59

610
@SpringBootApplication
11+
@EnableEncryptableProperties
712
public class Chapter15Application {
813

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+
}
1230

1331
}

2.x/chapter1-5/src/main/java/com/didispace/chapter15/HelloController.java

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11

2-
com.didispace.from=didi
2+
com.didispace.from1=didi
3+
com.didispace.from2=ENC(1I1oWHryzOJt+Gm81xnGnOUbBUpEBEFYES/NprA/q6ec3jBkU1xlBZWsHCaj71ds)
34

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
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

0 commit comments

Comments
 (0)