本地代码自动编译
This commit is contained in:
@@ -29,4 +29,4 @@ public class RuoYiApplication
|
||||
" | | \\ / \\ / \n" +
|
||||
" ''-' `'-' `-..-' ");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.ruoyi.web.core.config;
|
||||
|
||||
import org.apache.catalina.connector.Connector;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
|
||||
/**
|
||||
* DevTools 热重启配置 - 修复 Windows 下端口未释放问题
|
||||
* 启用 SO_REUSEADDR,允许 DevTools 重启时立即复用端口
|
||||
* 仅在本地开发环境生效,不影响线上
|
||||
*/
|
||||
@Profile("local")
|
||||
@Configuration
|
||||
public class DevToolsConfig implements WebServerFactoryCustomizer<TomcatServletWebServerFactory> {
|
||||
|
||||
@Override
|
||||
public void customize(TomcatServletWebServerFactory factory) {
|
||||
factory.addConnectorCustomizers((Connector connector) -> {
|
||||
connector.setProperty("socket.soReuseAddress", "true");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
server:
|
||||
# 服务器的HTTP端口,默认为8080
|
||||
port: 9091
|
||||
# 优雅关闭,防止 Windows 下 DevTools 重启时端口冲突
|
||||
shutdown: graceful
|
||||
servlet:
|
||||
# 应用的访问路径
|
||||
context-path: /
|
||||
@@ -50,6 +52,11 @@ spring:
|
||||
restart:
|
||||
# 热部署开关
|
||||
enabled: true
|
||||
# 变更检测后的静默期(ms),给 IDE 编译留时间
|
||||
quiet-period: 400
|
||||
lifecycle:
|
||||
# 优雅关闭超时
|
||||
timeout-per-shutdown-phase: 10s
|
||||
# redis 配置
|
||||
# token配置
|
||||
token:
|
||||
|
||||
73
watch.sh
Normal file
73
watch.sh
Normal file
@@ -0,0 +1,73 @@
|
||||
#!/bin/bash
|
||||
# 石河子后端 自动重启脚本
|
||||
# VS Code 保存 → Java 扩展编译 → 本脚本检测变更 → 杀旧进程 → 起新进程
|
||||
# 用法: bash watch.sh
|
||||
|
||||
SRC_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
cd "$SRC_DIR"
|
||||
|
||||
APP_CLASS="com.ruoyi.RuoYiApplication"
|
||||
PORT=9091
|
||||
|
||||
echo "================================================"
|
||||
echo " SHZ Backend 自动重启模式"
|
||||
echo " 流程: 保存文件 → Java扩展编译 → 检测变更 → 重启服务"
|
||||
echo " 端口: $PORT"
|
||||
echo " 按 Ctrl+C 退出"
|
||||
echo "================================================"
|
||||
|
||||
# 获取最新 .java 文件修改时间
|
||||
get_latest_mtime() {
|
||||
find . -name "*.java" -path "*/src/*" -type f -printf '%T@\n' 2>/dev/null | sort -rn | head -1 | cut -d'.' -f1
|
||||
}
|
||||
|
||||
# 精准杀后端进程
|
||||
kill_backend() {
|
||||
local pid=$(jps -l 2>/dev/null | grep "$APP_CLASS" | awk '{print $1}')
|
||||
if [ -n "$pid" ]; then
|
||||
echo "[$(date '+%H:%M:%S')] 🔪 终止旧进程 PID=$pid..."
|
||||
taskkill //PID "$pid" //F 2>/dev/null
|
||||
sleep 3
|
||||
# 确认端口已释放
|
||||
while netstat -ano 2>/dev/null | grep -q ":$PORT "; do
|
||||
sleep 2
|
||||
echo "[$(date '+%H:%M:%S')] ⏳ 等待端口 $PORT 释放..."
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# 启动服务
|
||||
start_server() {
|
||||
echo "[$(date '+%H:%M:%S')] 🚀 启动服务..."
|
||||
cd "$SRC_DIR"
|
||||
nohup mvn spring-boot:run -pl ruoyi-admin -DskipTests > /tmp/shz-backend.log 2>&1 &
|
||||
echo "[$(date '+%H:%M:%S')] 等待服务就绪..."
|
||||
for i in $(seq 1 90); do
|
||||
sleep 2
|
||||
curl -s --max-time 2 "http://localhost:$PORT/" > /dev/null 2>&1 && \
|
||||
echo "[$(date '+%H:%M:%S')] ✅ 服务已就绪: http://localhost:$PORT/" && \
|
||||
return 0
|
||||
done
|
||||
echo "[$(date '+%H:%M:%S')] ⚠️ 启动超时,查看 /tmp/shz-backend.log"
|
||||
}
|
||||
|
||||
# --- 主流程 ---
|
||||
|
||||
# 首次启动
|
||||
kill_backend
|
||||
start_server
|
||||
|
||||
last_ts=$(get_latest_mtime)
|
||||
|
||||
while true; do
|
||||
sleep 3
|
||||
current_ts=$(get_latest_mtime)
|
||||
|
||||
if [ -n "$current_ts" ] && [ -n "$last_ts" ] && [ "$current_ts" -gt "$last_ts" ]; then
|
||||
echo ""
|
||||
echo "[$(date '+%H:%M:%S')] 📝 检测到 .java 文件变更,重启服务..."
|
||||
kill_backend
|
||||
start_server
|
||||
last_ts=$(get_latest_mtime)
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user