Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc87112 committed Aug 13, 2021
1 parent e12aa4f commit e440510
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 18 deletions.
12 changes: 12 additions & 0 deletions 2.x/chapter1-5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand All @@ -41,6 +47,12 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-maven-plugin</artifactId>
<version>3.0.3</version>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
package com.didispace.chapter15;

import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@EnableEncryptableProperties
public class Chapter15Application {

public static void main(String[] args) {
SpringApplication.run(Chapter15Application.class, args);
}
public static void main(String[] args) {
SpringApplication.run(Chapter15Application.class, args);
}

@RestController
static class HelloController {

@Autowired
private JasyptExample jasyptExample;

@GetMapping("/hello")
public String hello() {
return "Hello World, " + jasyptExample.getFrom2();
}

}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.didispace.chapter15;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Slf4j
@Data
@Component
public class JasyptExample {

@Value("${com.didispace.from1:}")
private String from1;
@Value("${com.didispace.from2:}")
private String from2;

}
10 changes: 9 additions & 1 deletion 2.x/chapter1-5/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@

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

jasypt.encryptor.password=didispace

#[INFO] Encryptor config not found for property jasypt.encryptor.salt-generator-classname, using default value: org.jasypt.salt.RandomSaltGenerator
#[INFO] Encryptor config not found for property jasypt.encryptor.iv-generator-classname, using default value: org.jasypt.iv.RandomIvGenerator

# mvn jasypt:encrypt -Djasypt.encryptor.password=didispace
# mvn jasypt:decrypt -Djasypt.encryptor.password=didispace
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.didispace.chapter15;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@Slf4j
@SpringBootTest
public class PropertiesTest {

@Autowired
private JasyptExample jasyptExample;

@Test
public void test() {
log.info("from1 : {}", jasyptExample.getFrom1());
log.info("from2 : {}", jasyptExample.getFrom2());
}

}

0 comments on commit e440510

Please sign in to comment.