Files
AIGC/demo/start_with_dns_fix.ps1

34 lines
1.3 KiB
PowerShell
Raw Normal View History

# 启动Spring Boot应用修复DNS解析问题
# 添加JVM参数禁用DNS负缓存
Write-Host "=== 启动Spring Boot应用带DNS修复 ===" -ForegroundColor Green
$jvmArgs = @(
"-Dsun.net.inetaddr.ttl=60", # DNS成功缓存60秒
"-Dsun.net.inetaddr.negative.ttl=10", # DNS失败缓存10秒默认10分钟
"-Dnetworkaddress.cache.ttl=60", # 另一种DNS缓存设置
"-Dnetworkaddress.cache.negative.ttl=10", # 另一种DNS负缓存设置
"-jar",
"target/demo-0.0.1-SNAPSHOT.jar",
"--spring.profiles.active=dev"
)
Write-Host "启动参数: java $($jvmArgs -join ' ')" -ForegroundColor Yellow
try {
Start-Process -FilePath "java" -ArgumentList $jvmArgs -NoNewWindow -Wait:$false
Write-Host "✅ 应用启动命令已执行" -ForegroundColor Green
Write-Host "等待应用启动..." -ForegroundColor Yellow
Start-Sleep -Seconds 5
# 检查是否启动成功
$port8080 = netstat -ano | findstr :8080
if ($port8080) {
Write-Host "✅ 应用已启动 (端口8080)" -ForegroundColor Green
} else {
Write-Host "⚠ 应用可能还在启动中,请稍后检查日志" -ForegroundColor Yellow
}
} catch {
Write-Host "❌ 启动失败: $($_.Exception.Message)" -ForegroundColor Red
}