This repository has been archived by the owner on Dec 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
DemoApplication.java
52 lines (38 loc) · 1.57 KB
/
DemoApplication.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import java.sql.SQLException;
import static org.springframework.util.Assert.isTrue;
@SpringBootApplication
public class DemoApplication {
@Value("${spring.profiles.active:#{null}}")
private String profiles;
@Value("${spring.datasource.username}")
private String username;
@Value("${spring.datasource.password}")
private String password;
@Value("${other.username}")
private String other;
@Autowired
private DataSource dataSource;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@PostConstruct
private void postConstruct() throws SQLException {
System.out.println("##########################");
System.out.println("profile(s): " + profiles);
System.out.println("username: " + username);
System.out.println("password: " + password);
System.out.println("other: " + other);
dataSource.getConnection();
System.out.println("Successfully connected to database");
System.out.println("##########################");
isTrue (!username.equals("to-be-overwritten-by-vault-value"), "Username " + username);
isTrue (!password.equals("to-be-overwritten-by-vault-value"), "Password " + password);
}
}