Skip to content

Commit a5aa70b

Browse files
authored
Merge pull request #77 from Boyuan-IT-Club/Red_Moon
尝试隐藏秘钥等隐私字段
2 parents d102683 + 7fdcf62 commit a5aa70b

File tree

4 files changed

+39
-25
lines changed

4 files changed

+39
-25
lines changed

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,11 @@ build/
3232
### VS Code ###
3333
.vscode/
3434

35-
*.log
35+
*.log
36+
37+
### 配置文件 ###
38+
# 忽略本地配置文件
39+
.env
40+
.env.local
41+
.env.*.local
42+
!*.template

src/main/java/club/boyuan/official/OfficialApplication.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.mybatis.spring.annotation.MapperScan;
44
import org.springframework.boot.SpringApplication;
5-
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
65
import org.springframework.boot.autoconfigure.SpringBootApplication;
76
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
87

@@ -11,6 +10,17 @@
1110
public class OfficialApplication {
1211

1312
public static void main(String[] args) {
13+
// 检查关键环境变量是否已设置
14+
System.out.println("=== 环境变量检查 ===");
15+
String dbUsername = System.getenv("DB_USERNAME");
16+
String dbPassword = System.getenv("DB_PASSWORD");
17+
String jwtSecret = System.getenv("JWT_SECRET");
18+
19+
System.out.println("DB_USERNAME: " + (dbUsername != null ? "已设置" : "未设置"));
20+
System.out.println("DB_PASSWORD: " + (dbPassword != null ? "已设置" : "未设置"));
21+
System.out.println("JWT_SECRET: " + (jwtSecret != null ? "已设置" : "未设置"));
22+
System.out.println("==================");
23+
1424
SpringApplication.run(OfficialApplication.class, args);
1525
}
1626

src/main/resources/application-prod.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ spring:
22
application:
33
name: Official
44
datasource:
5-
url: jdbc:mysql://mysql:${MYSQL_PORT:3306}/${DB_NAME:official}?serverTimezone=UTC&allowPublicKeyRetrieval=true&useSSL=false
6-
username: ${DB_USERNAME:root}
7-
password: ${DB_PASSWORD:root}
5+
url: jdbc:mysql://mysql:${MYSQL_PORT}/${DB_NAME}?serverTimezone=UTC&allowPublicKeyRetrieval=true&useSSL=false
6+
username: ${DB_USERNAME}
7+
password: ${DB_PASSWORD}
88
driver-class-name: com.mysql.cj.jdbc.Driver
99
jpa:
1010
show-sql: true
@@ -13,15 +13,12 @@ spring:
1313
format_sql: true
1414
hibernate:
1515
ddl-auto: update
16-
# 移除数据库方言配置,让Hibernate自动检测
17-
# database-platform: org.hibernate.dialect.MySQL8Dialect
18-
# 明确关闭open-in-view以消除警告
1916
open-in-view: false
2017
mail:
21-
host: ${MAIL_HOST:smtp.feishu.cn}
22-
port: ${MAIL_PORT:465}
23-
username: ${MAIL_USERNAME:notify@boyuan.club}
24-
password: ${MAIL_PASSWORD:12bGmEWjvyRDjzxE}
18+
host: ${MAIL_HOST}
19+
port: ${MAIL_PORT}
20+
username: ${MAIL_USERNAME}
21+
password: ${MAIL_PASSWORD}
2522
properties:
2623
mail:
2724
smtp:
@@ -34,7 +31,7 @@ spring:
3431
data:
3532
redis:
3633
host: redis
37-
port: ${REDIS_PORT:6379}
34+
port: ${REDIS_PORT}
3835
password: ${REDIS_PASSWORD:}
3936
database: 0
4037
lettuce:
@@ -59,8 +56,8 @@ mybatis:
5956
mapUnderscoreToCamelCase: true
6057

6158
jwt:
62-
secret: ${JWT_SECRET:30b264511df560046ae9907e50cd6e69a3cb94ce987538fb2c90b98c70ce684a}
63-
expiration: ${JWT_EXPIRATION:86400000}
59+
secret: ${JWT_SECRET}
60+
expiration: ${JWT_EXPIRATION}
6461

6562
sms:
6663
access-key: ${SMS_ACCESS_KEY:your-sms-access-key}

src/main/resources/application.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ spring:
33
name: Official
44
datasource:
55
url: jdbc:mysql://localhost:3306/official?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
6-
username: root
7-
password: root
6+
username: ${DB_USERNAME}
7+
password: ${DB_PASSWORD}
88
driver-class-name: com.mysql.cj.jdbc.Driver
99
hikari:
1010
maximum-pool-size: 20
@@ -36,10 +36,10 @@ spring:
3636
max-idle: 8
3737
min-idle: 0
3838
mail:
39-
host: smtp.feishu.cn
40-
port: 465
41-
username: notify@boyuan.club
42-
password: 12bGmEWjvyRDjzxE
39+
host: ${MAIL_HOST}
40+
port: ${MAIL_PORT}
41+
username: ${MAIL_USERNAME}
42+
password: ${MAIL_PASSWORD}
4343
properties:
4444
mail:
4545
smtp:
@@ -56,13 +56,13 @@ mybatis:
5656
mapUnderscoreToCamelCase: true
5757

5858
jwt:
59-
secret: 30b264511df560046ae9907e50cd6e69a3cb94ce987538fb2c90b98c70ce684a
60-
expiration: 86400000
59+
secret: ${JWT_SECRET}
60+
expiration: ${JWT_EXPIRATION:86400000}
6161

6262
server:
6363
port: 8080
6464

6565
# 短信服务配置
6666
sms:
67-
access-key: your-sms-access-key
68-
secret-key: your-sms-secret-key
67+
access-key: ${SMS_ACCESS_KEY}
68+
secret-key: ${SMS_SECRET_KEY}

0 commit comments

Comments
 (0)