# Load env.secrets into current PowerShell process. Run before starting Java. # 文件内容即最终环境(正式服务器直接覆盖 env.secrets,bat 无需改)。 # # Usage: # cd E:\ylproject\project\ylrz_his_scrm_java # . .\scripts\load-env-secrets.ps1 # 本地若要用本机无密码 Redis,再执行: # . .\scripts\load-env-secrets.ps1 -LocalRedis param( [switch]$LocalRedis ) $root = Split-Path -Parent $PSScriptRoot $file = Join-Path $root "env.secrets" if (-not (Test-Path $file)) { $file = Join-Path $root "env.secrets.example" } if (-not (Test-Path $file)) { Write-Error "env.secrets not found"; return } Get-Content $file -Encoding UTF8 | ForEach-Object { $line = $_.Trim() if (-not $line -or $line.StartsWith("#")) { return } $idx = $line.IndexOf("=") if ($idx -lt 1) { return } $name = $line.Substring(0, $idx).Trim() $value = $line.Substring($idx + 1).Trim() Set-Item -Path ("Env:" + $name) -Value $value Write-Host ("SET " + $name) } Write-Host ("Loaded: " + $file) if ($LocalRedis) { Set-Item -Path "Env:HDT_REDIS_HOST" -Value "127.0.0.1" Set-Item -Path "Env:SPRING_REDIS_HOST" -Value "127.0.0.1" Set-Item -Path "Env:HDT_REDIS_PASSWORD" -Value "" Write-Host "Local override: Redis -> 127.0.0.1 (no password)" }