# example
server:
port: ${SERVER_PORT:8080}
special characters
about the Expression Language ( ${ } )
.
Use this character to set value
with default value
Environment Variable
SERVER_PORT, project work with the port you set, otherwise project work with the default port 8080.special character
, must add a Escape Character
.# application.yml
spring:
config:
import: "sm://"
datasource:
url: jdbc:postgresql://localhost:5432/cehr?currentSchema=XXXX
username: ${sm\://psql-username}
password: ${sm\://psql-password}
@Service
public class XXXService extends CommonService {
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
@Value("${sm://psql-username}")
private String username2;
@Value("${sm://psql-password}")
private String password2;
@Value("${sm\\://psql-username}")
private String username3;
@Value("${sm\\://psql-password}")
private String password3;
public void execute() {
System.out.println("username = " + username);
System.out.println("password = " + password);
System.out.println("username2 = " + username2);
System.out.println("password2 = " + password2);
System.out.println("username3 = " + username3);
System.out.println("password3 = " + password3);
System.out.println("psql-username = " + secretManagerTemplate.getSecretString("sm://psql-username"));
System.out.println("psql-password = " + secretManagerTemplate.getSecretString("sm://psql-password"));
}
}
# output
username = ********** (correct)
password = ********** (correct)
username2 = //psql-username
password2 = //psql-password
username3 = ********** (correct)
password3 = ********** (correct)
psql-username = ********** (correct)
psql-password = ********** (correct)
In this article, we found that how to use gcp secretmanager after Spring-Boot upgrade to version 3.4.0. I thing it's a luxurious trouble. Also see: Official website. Enjoy it.