当前位置: 首页 > news >正文

部署Spring Boot项目+mysql并允许前端本地访问的步骤

部署Spring Boot项目并允许前端访问的步骤指南

1. 服务器环境准备

确保服务器满足以下要求:
  • JDK 1.8
  • MySQL ≥5.7
  • Redis 5.0.3
  • Elasticsearch 6.8.6
  • Nginx 1.10.2

2. 安装必要组件

安装Java

bash

复制

下载

# 参考: https://blog.csdn.net/zhihui1017/article/details/51396706
sudo apt-get update
sudo apt-get install openjdk-8-jdk

安装MySQL

bash

复制

下载

# 参考: https://www.cnblogs.com/shenjianping/p/10984540.html
sudo apt-get install mysql-server

安装Nginx

bash

复制

下载

# 参考: https://blog.csdn.net/zlw_spider/article/details/100728525
sudo apt-get install nginx

安装Elasticsearch

bash

复制

下载

# 参考: https://blog.csdn.net/chijie6848/article/details/100643412
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.8.6.deb
sudo dpkg -i elasticsearch-6.8.6.deb

安装Redis

bash

复制

下载

# 参考: https://www.cnblogs.com/heqiuyong/p/10463334.html
sudo apt-get install redis-server

3. 配置服务

1. 启动MySQL、Elasticsearch和Redis服务 2. 修改Spring Boot配置文件:- `ruoyi-admin/src/main/resources/application.yml` - 配置Elasticsearch和Redis的主机和端口- `ruoyi-admin/src/main/resources/application_druid.yml` - 配置MySQL的URL、用户名和密码

4. 项目打包

后端打包

在`patent_search/bin`目录下运行`package.bat`,生成的jar包位于`patent_search/ruoyi-admin/target/ruoyi-admin.jar`

前端打包

在`patent_search/ruoyi-ui/bin`目录下运行`build.bat`,生成的`dist`文件夹位于`patent_search/ruoyi-ui/dist`

5. 部署到服务器

1. 使用WinSCP或其他工具将`ruoyi-admin.jar`和`dist`文件夹上传到服务器 2. 将`dist`文件夹内容放在Nginx的HTML目录下(通常为`/var/www/html`) 3. 配置Nginx(示例配置):

nginx

复制

下载

server {listen       80;server_name  your_server_ip;location / {root   /var/www/html/dist;index  index.html index.htm;try_files $uri $uri/ /index.html;}location /api {proxy_pass http://localhost:8080;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;}
}

6. 启动服务

1. 启动后端:

bash

复制

下载

nohup java -jar /path/to/ruoyi-admin.jar &

  1. 启动Nginx:

bash

复制

下载

sudo systemctl start nginx
# 或
/usr/local/nginx/sbin/nginx -s start

7. 开放服务器端口

在云服务器控制台安全组中开放以下端口:
  • 80端口(HTTP)
  • 8080端口(后端API,如果使用)
  • 其他需要的端口(如MySQL的3306等)

8. 访问前端

在其他电脑上通过浏览器访问服务器IP或域名即可访问前端界面。

更新部署流程

1. 上传新的`ruoyi-admin.jar`和`dist`文件夹到服务器 2. 停止旧的后端进程:

bash

复制

下载

netstat -apn | grep 8080  # 查找占用8080端口的进程
kill -9 <PID>             # 终止该进程
  1. 启动新的后端:

bash

复制

下载

nohup java -jar /path/to/ruoyi-admin.jar &

  1. 重新加载Nginx:

bash

复制

下载

/usr/local/nginx/sbin/nginx -s reload

注意事项

1. 确保Elasticsearch、MySQL、Redis服务正常运行 2. 在Linux环境下,确保`hanlp-wiki-vec-zh.txt`文件放在`/patent/`目录下 3. 检查所有服务的日志文件以排查问题 4. 考虑使用PM2等进程管理工具管理后端服务

按照以上步骤操作,您的Spring Boot项目应该能够成功部署,并且前端可以在其他电脑上通过浏览器访问服务器上的应用。

:::info
这样就可以在其他电脑本地启动前端时看到后端数据吗

:::

要使本地启动的前端能够访问服务器上的后端数据,需要确保以下几点:


**1. 确保后端API可被外部访问**

**检查后端是否运行并暴露了正确的端口**

+ 你的 `ruoyi-admin.jar` 应该在服务器上运行,并监听某个端口(如 `8080`)。

检查后端是否启动:

  • bash复制下载netstat -tulnp | grep java # 或 grep 8080

如果看到类似 0.0.0.0:8080:::8080,说明后端已监听所有网络接口,可被外部访问。

**检查服务器防火墙/安全组**

+ **云服务器(阿里云/腾讯云/AWS等)**:确保安全组规则允许 `8080` 端口(或你的后端端口)的入站流量。 + **本地服务器(如公司内网)**:- 检查 `iptables`/`firewalld` 是否放行端口:

bash

复制

下载

sudo ufw allow 8080  # Ubuntu
sudo firewall-cmd --add-port=8080/tcp --permanent  # CentOS
sudo firewall-cmd --reload

**2. 修改前端代码的API请求地址**

**情况1:前端打包后部署在服务器(Nginx代理)**

+ 前端打包后,Nginx 配置通常如下:

nginx

复制

下载

server {listen 80;server_name your-server-ip;location / {root /var/www/html/dist;index index.html;}location /api {proxy_pass http://localhost:8080;  # 后端运行在8080}
}
- 这样,前端访问 `/api` 会自动代理到后端 `8080` 端口,无需额外配置。

**情况2:前端在本地开发环境运行(未打包)**

如果你的前端是 `Vue/React` 项目,仍在本地开发环境运行(如 `npm run dev`),则需要修改 API 请求地址,使其指向**服务器后端**:
**(1)修改前端环境变量**
+ **Vue 项目**(如 `vue.config.js`):

js

复制

下载

module.exports = {devServer: {proxy: {'/api': {target: 'http://你的服务器IP:8080',  // 后端地址changeOrigin: true,pathRewrite: {'^/api': ''}}}}
}
  • React 项目(如 package.json.env):

env

复制

下载

REACT_APP_API_BASE_URL=http://你的服务器IP:8080

然后在代码中使用:

js

复制

下载

axios.get(${process.env.REACT_APP_API_BASE_URL}/api/data);

**(2)直接修改请求URL**
如果前端代码直接写死了 `http://localhost:8080`,则需要改成服务器IP:

js

复制

下载

axios.get(“http://你的服务器IP:8080/api/data”);


**3. 解决跨域问题(如果前端在本地运行)**

如果前端在本地 `http://localhost:3000`,而后端在 `http://服务器IP:8080`,浏览器会阻止跨域请求(CORS)。

**解决方案**

**(1)后端允许跨域**
在 Spring Boot 的 `application.yml` 或 `@Configuration` 类中添加:

java

复制

下载

@Configuration
public class CorsConfig implements WebMvcConfigurer {@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**").allowedOrigins("*")  // 允许所有来源(或指定前端地址).allowedMethods("GET", "POST", "PUT", "DELETE").allowedHeaders("*");}
}
**(2)Nginx 反向代理(推荐)**
如果后端和前端都通过 Nginx 访问,则不会有跨域问题(因为域名相同)。

**4. 测试访问**

**(1)直接访问后端API**

在浏览器或 Postman 访问:

复制

下载

http://你的服务器IP:8080/api/test

如果返回数据,说明后端可被外部访问。

**(2)本地前端访问后端**

+ 如果前端在本地运行,确保修改了 API 请求地址(如 `http://服务器IP:8080/api`)。 + 如果出现跨域错误,检查后端 CORS 配置或使用 Nginx 代理。

**总结**

| **情况** | **解决方案** | | --- | --- | | **前端打包后部署在服务器(Nginx代理)** | Nginx 自动代理 `/api`
到后端,无需额外配置 | | **前端在本地运行,访问远程后端** | 修改前端请求地址为 `http://服务器IP:8080`
,并确保后端允许跨域 | | **后端无法访问** | 检查服务器防火墙、安全组、后端是否监听 `0.0.0.0` |

按照以上步骤调整后,你的本地前端应该可以正常访问服务器后端数据

:::info
整合一下,我需要怎么做,我的前端是vue,在本地运行,后端和MYSQL要打包到服务器

:::

**完整部署方案(本地Vue前端 + 服务器Spring Boot后端 & MySQL)**

**目标**

+ **前端**:Vue 项目,在本地开发环境运行(`npm run dev`) + **后端**:Spring Boot + MySQL,打包成 `jar` 并部署到服务器 + **要求**:本地前端能访问服务器上的后端API

**步骤 1:服务器环境准备**

确保服务器已安装:
  • JDK 1.8+
  • MySQL 5.7+
  • (可选)Redis / Elasticsearch(如果你的项目需要)

**(1)安装Java**

bash

复制

下载

sudo apt update
sudo apt install openjdk-8-jdk

验证:

bash

复制

下载

java -version

**(2)安装MySQL**

bash

复制

下载

sudo apt install mysql-server
sudo mysql_secure_installation  # 设置root密码

登录MySQL并创建数据库:

bash

复制

下载

mysql -u root -p

sql

复制

下载

CREATE DATABASE your_db_name;
CREATE USER 'your_user'@'%' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_db_name.* TO 'your_user'@'%';
FLUSH PRIVILEGES;

**步骤 2:打包并上传Spring Boot后端**

**(1)修改后端配置**

确保 `application.yml` 或 `application.properties` 中的数据库连接指向**服务器MySQL**:

yaml

复制

下载

spring:datasource:url: jdbc:mysql://服务器IP:3306/your_db_name?useSSL=falseusername: your_userpassword: your_password

**(2)打包Spring Boot项目**

bash

复制

下载

mvn clean package -DskipTests

生成的 jar 文件在 target/your-project.jar

**(3)上传到服务器**

使用 `scp` 或 WinSCP 上传:

bash

复制

下载

scp target/your-project.jar user@服务器IP:/home/your_project/

**(4)在服务器运行后端**

bash

复制

下载

nohup java -jar /home/your_project/your-project.jar --server.port=8080 &

检查是否运行:

bash

复制

下载

ps aux | grep java
netstat -tulnp | grep 8080

**步骤 3:配置本地Vue前端访问服务器API**

**(1)修改Vue的API请求地址**

在 `vue.config.js` 中配置代理:

js

复制

下载

module.exports = {devServer: {proxy: {'/api': {target: 'http://服务器IP:8080',  // 后端地址changeOrigin: true,pathRewrite: {'^/api': ''}}}}
}

或者在 .env.development 中设置:

env

复制

下载

VUE_APP_API_BASE_URL=http://服务器IP:8080

然后在代码中使用:

js

复制

下载

axios.get(${process.env.VUE_APP_API_BASE_URL}/api/data);

**(2)解决跨域问题**

如果后端未配置 CORS,在 Spring Boot 中添加:

java

复制

下载

@Configuration
public class CorsConfig implements WebMvcConfigurer {@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**").allowedOrigins("*")  // 允许所有来源(或指定前端地址).allowedMethods("GET", "POST", "PUT", "DELETE").allowedHeaders("*");}
}

**步骤 4:测试访问**

**(1)直接访问后端API**

在浏览器或 Postman 访问:

复制

下载

http://服务器IP:8080/api/test

如果返回数据,说明后端正常运行。

**(2)本地Vue访问**

运行本地前端:

bash

复制

下载

npm run dev

访问 http://localhost:8080,检查是否能获取服务器数据。


**可能出现的问题 & 解决方案**

| **问题** | **解决方案** | | --- | --- | | **本地前端无法访问后端API** | 检查 `vue.config.js`
代理配置,确保后端IP正确 | | **后端连接MySQL失败** | 检查 `application.yml`
的数据库配置,确保MySQL允许远程连接 | | **跨域错误(CORS)** | 后端配置 `CorsConfig`
或使用 Nginx 反向代理 | | **服务器端口无法访问** | 检查防火墙 (`ufw`
/`firewalld`
) 和云服务器安全组 |

**总结**

1. **服务器**:安装 JDK + MySQL,运行 Spring Boot `jar`。 2. **本地Vue**:修改 `vue.config.js` 代理,指向服务器API。 3. **测试**:确保后端可访问,前端能获取数据。

这样,你的本地Vue前端就可以访问服务器上的Spring Boot后端 & MySQL了! 🚀

:::info
服务器IP是公网IP吗

:::

是的,服务器IP通常指的是公网IP(如果你的服务器在云平台如阿里云、腾讯云、AWS等),这样你的本地前端才能通过互联网访问它。但具体情况取决于你的服务器部署方式:


**1. 服务器IP的类型**

| **IP类型** | **说明** | **适用场景** | | --- | --- | --- | | **公网IP** | 全球可访问,如 `123.123.123.123` | 云服务器(阿里云/腾讯云/AWS等) | | **内网IP** | 仅局域网内可访问,如 `192.168.1.100` | 本地物理服务器、公司内网 | | **弹性IP**(EIP) | 云平台提供的固定公网IP | 避免云服务器重启后IP变化 |

**2. 如何确认你的服务器IP是公网IP?**

**(1)云服务器(阿里云/腾讯云/AWS等)**
+ 登录云平台控制台,查看实例详情中的 **“公网IP”** 或 **“弹性公网IP”**。 + 示例:

复制

下载

公网IP: 123.123.123.123
内网IP: 10.0.0.2

你需要用公网IP让本地前端访问!

**(2)本地物理服务器/家用电脑**
+ 如果你的服务器是本地电脑或公司内网机器,可能没有公网IP。 + 检查IP:

bash

复制

下载

curl ifconfig.me  # Linux/Mac获取公网IP
ipconfig         # Windows查看内网IP
- 如果返回的IP是 `192.168.x.x` 或 `10.x.x.x`,说明是内网IP,**外部无法直接访问**。

**3. 无公网IP怎么办?**

如果你的服务器只有内网IP(如家用电脑),可通过以下方式让本地前端访问:
**(1)内网穿透工具**
+ **Ngrok** / **FRP**:将内网服务映射到公网域名。

bash

复制

下载

ngrok http 8080 # 生成一个临时公网URL,如 https://abc123.ngrok.io

前端配置:

js

复制

下载

axios.get(“https://abc123.ngrok.io/api/data”);

**(2)云服务器反向代理**
+ 如果你有一台云服务器,可用Nginx反向代理到内网机器:

nginx

复制

下载

server {listen 80;server_name your-domain.com;location / {proxy_pass http://内网IP:8080;  # 如 http://192.168.1.100:8080}
}
**(3)VPN/ZeroTier**
+ 通过VPN将本地前端和服务器置于同一虚拟局域网(如ZeroTier)。

**4. 安全注意事项**

1. **不要直接暴露MySQL到公网**- 确保MySQL仅允许内网连接(如 `bind-address = 127.0.0.1`)。- 如果前端需直连MySQL(不推荐),用SSH隧道:

bash

复制

下载

ssh -L 3306:localhost:3306 user@服务器IP
  1. 保护后端API
    • 使用HTTPS(Nginx配置SSL证书)。
    • 添加API鉴权(如JWT)。

**总结**

+ **如果服务器在云平台** → 用控制台提供的**公网IP**(如 `123.123.123.123`)。 + **如果是家用电脑/内网服务器** → 需内网穿透(Ngrok/FRP)或VPN。 + **永远不要直接暴露数据库到公网!**

确认IP后,按之前的步骤配置即可! 🎯

本回答由 AI 生成,内容仅供参考,请仔细甄别。

:::info
PS C:\Users\17035\Desktop\新建文件夹\back-end-of-western-restaurant - 副本\dish\target> java -jar ngpos-boot3-1.0.jar ngpos-boot3-1.0.jar中没有主清单属性

:::

这个错误 “jar中没有主清单属性” 是因为你的 Spring Boot 项目打包时没有正确生成 MANIFEST.MF 文件,导致 Java 无法识别哪个类是主类(Main-Class)。以下是解决方案:


**1. 问题原因**

Spring Boot 的 `jar` 包需要包含 `META-INF/MANIFEST.MF` 文件,其中指定:
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.your.package.MainApplication

如果缺失这些信息,运行 java -jar 时会报错。


**2. 解决方案**

**(1)检查**** **`**pom.xml**`** ****是否包含**** **`**spring-boot-maven-plugin**`

确保你的 `pom.xml` 有以下插件配置:
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>3.1.0</version> <!-- 使用你的Spring Boot版本 --></plugin></plugins>
</build>

**(2)重新打包**

在项目根目录运行:

bash

复制

下载

mvn clean package -DskipTests

或(如果你用 Gradle):

bash

复制

下载

./gradlew clean bootJar

**(3)验证**** **`**MANIFEST.MF**`

解压生成的 `jar` 文件,检查 `META-INF/MANIFEST.MF`:

bash

复制

下载

unzip -l ngpos-boot3-1.0.jar | grep META-INF/MANIFEST.MF

或直接查看内容:

bash

复制

下载

unzip -p ngpos-boot3-1.0.jar META-INF/MANIFEST.MF

正常情况应包含:

plaintext

复制

下载

Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.your.package.MainApplication

**3. 如果仍然失败**

**(1)手动指定主类运行**

bash

复制

下载

java -cp ngpos-boot3-1.0.jar com.your.package.MainApplication

(替换 com.your.package.MainApplication 为你的启动类)

**(2)检查是否误打包为普通**** **`**jar**`

如果使用 `mvn package` 而非 `spring-boot-maven-plugin`,可能会生成非可执行 `jar`。确保使用:

bash

复制

下载

mvn spring-boot:repackage

**(3)检查 IDE 打包配置**

+ **IntelliJ IDEA**: `Run → Edit Configurations → Build → 确保勾选 "Build on Make"` + **Eclipse**: `右键项目 → Run As → Maven Build → Goals: clean package`

**4. 常见错误排查**

| **错误现象** | **解决方案** | | --- | --- | | `no main manifest attribute` | 检查 `spring-boot-maven-plugin`
是否缺失 | | `ClassNotFoundException` | 确保 `Start-Class`
在 `MANIFEST.MF`
中正确 | | 打包后无 `BOOT-INF/` | 可能是普通 `jar`
,需用 `spring-boot-maven-plugin` |

**5. 最终解决方案**

如果所有方法无效,可以 **手动生成**** **`**MANIFEST.MF**`:
  1. 创建 src/main/resources/META-INF/MANIFEST.MF
Manifest-Version: 1.0
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.your.package.MainApplication
  1. pom.xml 中禁用默认生成:
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><configuration><archive><manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile></archive></configuration>
</plugin>

**总结**

1. **确保**** **`**pom.xml**`** ****有**** **`**spring-boot-maven-plugin**` 2. **运行**** **`**mvn clean package**` 3. **检查**** **`**MANIFEST.MF**`** ****是否包含**** **`**Main-Class**`** ****和**** **`**Start-Class**`

99% 的问题都是由于 插件缺失或打包方式错误,按照上述步骤修复即可! 🚀

:::info
C:\Users\17035\Desktop\新建文件夹\back-end-of-western-restaurant 2>mvn clean package [INFO] Scanning for projects… [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.064 s [INFO] Finished at: 2025-05-04T22:23:19+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] The goal you specified requires a project to execute but there is no POM in this directory (C:\Users\17035\Desktop\鏂板缓鏂囦欢澶筡back-end-of-western-restaurant 2). Please verify you invoked Maven from the correct directory. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MissingProjectException

:::

这个错误表明 Maven 无法找到** **pom.xml** **文件,导致构建失败。以下是详细解决方案:


**1. 问题原因**

错误信息关键点:

复制

下载

[ERROR] No POM in this directory (C:\Users\17035\Desktop\鏂板缓鏂囦欢澶筡back-end-of-western-restaurant 2)

原因:

  • 当前目录下没有 pom.xml(Maven 的项目配置文件)。
  • 目录路径可能包含 中文或特殊字符(如鏂板缓鏂囦欢澶筡),导致 Maven 解析异常。

**2. 解决方案**

**(1)确认项目目录结构**

进入项目根目录,确保存在 `pom.xml`:

bash

复制

下载

cd C:\Users\17035\Desktop\back-end-of-western-restaurant 2
dir  # Windows 列出文件(应看到 pom.xml)

如果 pom.xml 在其他子目录(如 dish),需进入正确目录:

cd C:\Users\17035\Desktop\back-end-of-western-restaurant 2\dish

**(2)修复路径中的中文/特殊字符**

如果路径包含中文(如 `新建文件夹`)或乱码:
  • 方法1:重命名路径为纯英文(如 C:\Users\17035\Desktop\restaurant-backend)。
  • 方法2:将项目移动到简单路径(如 C:\projects)。

**(3)手动指定**** **`**pom.xml**`

如果文件存在但 Maven 仍报错,强制指定 `pom.xml`:
mvn -f pom.xml clean package

**(4)检查文件编码问题**

如果路径显示为乱码(如`鏂板缓鏂囦欢澶筡`),可能是系统编码问题:
  • 在命令提示符中执行:

bash

复制

下载

chcp 65001 # 切换为UTF-8编码

  • 或使用 PowerShellGit Bash 替代默认的 cmd

**3. 验证是否成功**

1. 进入正确的项目目录:

cd C:\Users\17035\Desktop\restaurant-backend\dish

  1. 运行 Maven:

mvn clean package

  1. 成功后会在 target/ 下生成 jar 文件。

**4. 常见问题**

| **问题现象** | **解决方案** | | --- | --- | | `No POM in this directory` | 检查是否在含 `pom.xml`
的目录执行命令 | | 路径含中文/空格 | 重命名路径为英文,或使用短路径(如 `C:\projects`
) | | 乱码错误 | 切换终端编码(`chcp 65001`
)或换用 PowerShell |

**5. 预防措施**

1. **项目路径尽量用英文**(如 `C:\projects\restaurant-backend`)。 2. 在 IDE(如 IntelliJ/VSCode)中直接右键 `pom.xml` 运行 Maven 命令,避免路径错误。

按照以上步骤操作后,你的 Maven 构建应该能正常执行!如果仍有问题,请提供完整的目录结构和 pom.xml 位置。

:::info
Downloaded from aliyunmaven: https://maven.aliyun.com/repository/public/org/codehaus/plexus/plexus-compiler-javac/2.8.4/plexus-compiler-javac-2.8.4.jar (21 kB at 8.5 kB/s) Downloaded from aliyunmaven: https://maven.aliyun.com/repository/public/com/thoughtworks/qdox/qdox/2.0-M9/qdox-2.0-M9.jar (317 kB at 127 kB/s) [INFO] Changes detected - recompiling the module! [INFO] Compiling 64 source files to C:\Users\17035\Desktop\west\back-end-of-western-restaurant 2\dish\target\classes [INFO] /C:/Users/17035/Desktop/west/back-end-of-western-restaurant 2/dish/src/main/java/com/example/dish/pos/controller/OrderController.java: 鏌愪簺杈撳叆鏂囦欢浣跨敤浜嗘湭缁忔鏌ユ垨涓嶅畨鍏ㄧ殑鎿嶄綔銆 [INFO] /C:/Users/17035/Desktop/west/back-end-of-western-restaurant 2/dish/src/main/java/com/example/dish/pos/controller/OrderController.java: 鏈夊叧璇︾粏淇℃伅, 璇蜂娇鐢?-Xlint:unchecked 閲嶆柊缂栬瘧銆倐 [INFO] [INFO] — resources:3.3.1:testResources (default-testResources) @ ngpos-boot3 — [INFO] skip non existing resourceDirectory C:\Users\17035\Desktop\west\back-end-of-western-restaurant 2\dish\src\test\resources [INFO] [INFO] — compiler:3.8.1:testCompile (default-testCompile) @ ngpos-boot3 — [INFO] Changes detected - recompiling the module! [INFO] Compiling 1 source file to C:\Users\17035\Desktop\west\back-end-of-western-restaurant 2\dish\target\test-classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /C:/Users/17035/Desktop/west/back-end-of-western-restaurant 2/dish/src/test/java/com/example/dish/DishApplicationTests.java:[29,25] 鎵句笉鍒扮鍙? 绗﹀彿: 鏂规硶 setCategoryName(java.lang.String) 浣嶇疆: 绫诲瀷涓篶om.example.dish.pos.domain.Category鐨勫彉閲?categoryry [INFO] 1 error [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:51 min [INFO] Finished at: 2025-05-04T22:27:22+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project ngpos-boot3: Compilation failure [ERROR] /C:/Users/17035/Desktop/west/back-end-of-western-restaurant 2/dish/src/test/java/com/example/dish/DishApplicationTests.java:[29,25] 鎵句笉鍒扮鍙?[mm [ERROR] 绗﹀彿: 鏂规硶 setCategoryName(java.lang.String) [ERROR] 浣嶇疆: 绫诲瀷涓篶om.example.dish.pos.domain.Category鐨勫彉閲?categorym [ERROR] [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

:::

这个错误是由于 测试代码调用了不存在的方法 setCategoryName() 导致的编译失败。以下是完整的解决方案:


**1. 错误分析**

关键错误信息:

复制

下载

[ERROR] 找不到符号 [mm符号:   方法 setCategoryName(java.lang.String)位置: 类型为com.example.dish.pos.domain.Category的变量 categorym

说明:

  • 测试类 DishApplicationTests.java 第29行尝试调用 category.setCategoryName() 方法。
  • Category 类中并没有这个方法(可能是拼写错误或方法未定义)。

**2. 解决方案**

**(1)检查**** **`**Category**`** ****类的方法**

找到 `com.example.dish.pos.domain.Category` 类,确认是否包含:

java

复制

下载

public class Category {// 检查是否有 setCategoryName() 方法public void setCategoryName(String name) {this.categoryName = name;}
}

如果方法名不一致(如 setName),需修改测试代码。

**(2)修正测试代码**

修改 `DishApplicationTests.java` 第29行:

java

复制

下载

// 原错误代码(假设):
category.setCategoryName("饮料");// 修正为实际存在的方法(例如):
category.setName("饮料");  // 或 category.setCategory("饮料");

**(3)跳过测试(临时方案)**

如果急需打包,可跳过测试:

bash

复制

下载

mvn clean package -DskipTests


**3. 其他可能的问题**

**(1)编码问题**

日志中的中文乱码(如 `鏌愪簺杈撳叆鏂囦欢`)是系统编码问题,但不影响编译。 可修复终端编码:

bash

复制

下载

chcp 65001 # Windows 切换为 UTF-8

**(2)依赖问题**

如果 `Category` 类来自其他模块,确保依赖已正确引入:

xml

复制

下载

运行

<dependency><groupId>com.example</groupId><artifactId>dish-domain</artifactId><version>1.0</version>
</dependency>

**4. 完整修复步骤**

1. **定位错误文件** 打开 `DishApplicationTests.java`,找到第29行。 2. **检查**** **`**Category**`** ****类** 确认 `setCategoryName()` 是否存在,或正确方法名是什么。 3. **同步代码**- 如果方法名错误 → 修正测试代码。- 如果方法缺失 → 在 `Category` 类中添加方法。 4. **重新编译**

bash

复制

下载

mvn clean package


**5. 示例修正**

假设 `Category` 类实际方法是 `setName()`:

java

复制

下载

// 原错误代码
category.setCategoryName("饮料");// 修正后
category.setName("饮料");

**总结**

| **问题类型** | **解决方案** | | --- | --- | | **方法不存在** | 检查 `Category`
类并修正测试代码 | | **拼写错误** | 统一方法名(如 `setName`
vs `setCategoryName`
) | | **依赖缺失** | 确保 `Category`
类所在的模块已被引入 | | **紧急打包** | 使用 `-DskipTests`
跳过测试 |

按步骤操作后,重新运行 mvn clean package 即可成功构建! 🚀

:::info
在服务器运行后端 bash nohup java -jar /home/your_project/your-project.jar --server.port=8080 &我是Windows服务器怎么办

:::

Windows 服务器 上运行 Spring Boot 的 JAR 文件与 Linux 有所不同。以下是针对 Windows 的详细部署步骤:


**1. 直接运行(临时测试)**

**方法1:命令行启动**

cmd

复制

下载

java -jar C:\path\to\your-project.jar --server.port=8080
  • 问题:关闭窗口后进程终止。

**方法2:后台运行(类似**** **`**nohup**`**)**

cmd

复制

下载

start /B javaw -jar C:\path\to\your-project.jar --server.port=8080

  • javaw:无控制台窗口的后台运行。
  • 日志:默认输出到 nohup.out(需手动重定向)。

**2. 作为 Windows 服务运行(推荐)**

**步骤1:使用**** **`**winsw**`** ****工具**

1. 下载 [winsw](https://github.com/winsw/winsw/releases),将 `WinSW.NET4.exe` 重命名为 `MyAppService.exe`。 2. 同目录下创建 `MyAppService.xml`:

xml

复制

下载

运行

<service><id>MyApp</id><name>My Spring Boot App</name><description>运行后端服务</description><executable>java</executable><arguments>-jar "C:\path\to\your-project.jar" --server.port=8080</arguments><logmode>rotate</logmode>
</service>
  1. 安装服务:

cmd

复制

下载

MyAppService.exe install

  1. 启动服务:

cmd

复制

下载

net start MyApp

**步骤2:使用 NSSM(更简单)**

1. 下载 [NSSM](https://nssm.cc/download)。 2. 安装服务:

cmd

复制

下载

nssm install MyApp

- 在 GUI 中设置:* **Path**: `java.exe`* **Arguments**: `-jar "C:\path\to\your-project.jar" --server.port=8080`* **Startup directory**: 选择 JAR 所在目录。
  1. 启动服务:

cmd

复制

下载

nssm start MyApp


**3. 日志管理**

**(1)输出到文件**

cmd

复制

下载

java -jar C:\path\to\your-project.jar --server.port=8080 > C:\logs\app.log 2>&1

**(2)使用 Logback 或 Log4j2**

在 `application.properties` 中配置:

properties

复制

下载

logging.file.path=C:/logs
logging.file.name=myapp.log

**4. 开机自启动**

**方法1:通过服务**

若使用 `winsw` 或 `NSSM`,服务默认会开机启动。

**方法2:任务计划程序**

1. 按 `Win + R`,输入 `taskschd.msc`。 2. 创建任务:- **触发器**:登录时。- **操作**:启动程序 `java.exe`,参数 `-jar C:\path\to\your-project.jar`。

**5. 防火墙配置**

确保 Windows 防火墙允许端口 `8080`:

powershell

复制

下载

New-NetFirewallRule -DisplayName “Allow Spring Boot Port” -Direction Inbound -LocalPort 8080 -Protocol TCP -Action Allow


**常见问题解决**

| **问题** | **解决方案** | | | --- | --- | --- | | **端口占用** | `netstat -ano | findstr 8080`+`
taskkill /PID /F` | | **Java 未找到** | 添加 Java 到 PATH 或使用绝对路径 `"C:\Program Files\Java\bin\java.exe"` | | | **服务启动失败** | 检查事件查看器(`eventvwr.msc`
)中的错误日志 | |

**总结**

+ **临时测试**:用 `javaw -jar` 后台运行。 + **长期运行**:通过 `winsw` 或 `NSSM` 注册为服务。 + **生产环境**:务必配置日志和开机自启动。

这样你的 Spring Boot 应用就能在 Windows 服务器上稳定运行了! 🚀

C:\Users\Administrator>java -jar C:\Users\Administrator\Desktop\ngpos-boot3-1.0.jar --server.port=8081 C:\Users\Administrator\Desktop\ngpos-boot3-1.0.jar中没有主清单属性

这个错误表明你的 JAR 文件缺少 MANIFEST.MF 中的 Main-Class 定义,导致 Java 无法识别启动类。以下是完整的解决方案:


**1. 问题原因**

Spring Boot 可执行 JAR 需要包含以下内容:

bash

复制

下载

META-INF/MANIFEST.MF 中必须包含:
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.example.your.MainApplication

你的 JAR 文件打包时未正确生成这些信息。


**2. 快速解决方案**

**方法1:通过 Maven 重新正确打包**
1. 确保项目根目录有 `pom.xml` 且包含插件:

xml

复制

下载

运行

<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>3.1.0</version> <!-- 与你的Spring Boot版本一致 --></plugin></plugins>
</build>
  1. 重新打包:

bash

复制

下载

mvn clean package -DskipTests

  1. 检查生成的 JAR:

bash

复制

下载

unzip -l target/ngpos-boot3-1.0.jar | grep META-INF/MANIFEST.MF

**方法2:手动指定主类运行**
如果无法重新打包,直接指定启动类:

bash

复制

下载

java -cp C:\Users\Administrator\Desktop\ngpos-boot3-1.0.jar com.example.your.MainApplication --server.port=8081

(替换 com.example.your.MainApplication 为你的实际启动类)


**3. 深度修复步骤**

**步骤1:验证 JAR 结构**
检查 JAR 是否包含 Spring Boot 的层级结构:

bash

复制

下载

# 应该看到 BOOT-INF/classes/ 和 BOOT-INF/lib/
jar tf C:\Users\Administrator\Desktop\ngpos-boot3-1.0.jar

如果只有 WEB-INF/,说明打包成了普通 JAR 而非 Spring Boot JAR。

**步骤2:修复打包方式**
+ **错误方式**:使用了 `maven-jar-plugin` 而非 `spring-boot-maven-plugin`。 + **正确配置**:

xml

复制

下载

运行

<plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><executions><execution><goals><goal>repackage</goal> <!-- 关键!会生成可执行JAR --></goals></execution></executions>
</plugin>
**步骤3:手动生成 MANIFEST.MF(终极方案)**
1. 创建 `src/main/resources/META-INF/MANIFEST.MF`:

plaintext

复制

下载

Manifest-Version: 1.0
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.example.your.MainApplication
  1. pom.xml 中禁用默认生成:

xml

复制

下载

运行

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><configuration><archive><manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile></archive></configuration>
</plugin>

**4. 常见问题排查**

| **现象** | **解决方案** | | --- | --- | | 打包后无 `BOOT-INF/` | 确认使用了 `spring-boot-maven-plugin` | | `Start-Class`
未定义 | 检查启动类是否在 `MANIFEST.MF`
中 | | 依赖缺失 | 确保 `jar`
而非 `war` |

**5. 验证成功**

运行以下命令应正常启动:

bash

复制

下载

java -jar target/ngpos-boot3-1.0.jar --server.port=8081


**总结**

1. **99% 的问题** 是由于未正确使用 `spring-boot-maven-plugin`。 2. 按上述步骤重新打包后,`MANIFEST.MF` 会自动包含必要信息。 3. 如果仍失败,检查项目结构是否完整(启动类必须在主代码目录中)。

C:\Users\Administrator>java -cp C:\Users\Administrator\Desktop\ngpos-boot3-1.0.jar com.example.dish.DishApplication --server.port=8081 Exception in thread “main” java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication at com.example.dish.DishApplication.main(DishApplication.java:12) Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:490) … 1 more

The server is busy. Please try again later.

检查生成的 JAR: bash unzip -l target/ngpos-boot3-1.0.jar | grep META-INF/MANIFEST.MF 我是windows系统

在 Windows 系统上检查 JAR 文件中的 MANIFEST.MF,可以使用以下命令替代 Linux 的 unzipgrep


**1. 使用**** **`**jar**`** ****命令查看 MANIFEST.MF**

cmd

复制

下载

jar tf C:\path\to\ngpos-boot3-1.0.jar | findstr META-INF/MANIFEST.MF

  • 说明
    • jar tf:列出 JAR 文件内容。
    • findstr:Windows 下的文本搜索工具(类似 Linux 的 grep)。

**2. 直接解压并查看 MANIFEST.MF**

cmd

复制

下载

# 解压到临时目录
mkdir temp
cd temp
jar xf C:\path\to\ngpos-boot3-1.0.jar# 查看 MANIFEST.MF 内容
type META-INF\MANIFEST.MF
  • 关键检查项

plaintext

复制

下载

Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.example.your.MainApplication

如果缺失这两项,说明打包有问题。


**3. 使用压缩软件直接查看**

1. 右键 `ngpos-boot3-1.0.jar` → 用压缩软件(如 WinRAR/7-Zip)打开。 2. 进入 `META-INF/` 目录,双击 `MANIFEST.MF` 查看内容。

**4. 常见问题排查**

**(1)如果 MANIFEST.MF 不存在**
+ 原因:未正确使用 `spring-boot-maven-plugin` 打包。 + 解决:在 `pom.xml` 中添加插件:

xml

复制

下载

运行

<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins>
</build>

然后重新打包:

cmd

复制

下载

mvn clean package

**(2)如果 MANIFEST.MF 内容不全**
+ 示例错误:

plaintext

复制

下载

Manifest-Version: 1.0

缺少 Main-ClassStart-Class

  • 解决:按上文方法手动生成或修复 pom.xml

**5. 验证修复后重新运行**

cmd

复制

下载

java -jar C:\path\to\ngpos-boot3-1.0.jar --server.port=8081


**总结**

| **步骤** | **Windows 命令** | | --- | --- | | **列出 JAR 内容** | `jar tf your.jar | findstr META-INF/MANIFEST.MF` | | **解压查看文件** | `jar xf your.jar`
+ `type META-INF\MANIFEST.MF` | | **图形化查看** | 用 WinRAR/7-Zip 直接打开 JAR |

通过以上方法,你可以确认 JAR 包是否正确打包,并修复 MANIFEST.MF 缺失的问题!

Manifest-Version: 1.0 Created-By: Maven JAR Plugin 3.3.0 Build-Jdk-Spec: 22 MANIFEST.MF文件内容

从你提供的 MANIFEST.MF 内容来看,这个 JAR 文件 缺少 Spring Boot 可执行 JAR 必需的关键属性,导致无法通过 java -jar 直接运行。以下是详细分析和解决方案:


**1. 问题分析**

你的 `MANIFEST.MF` 内容:

plaintext

复制

下载

Manifest-Version: 1.0
Created-By: Maven JAR Plugin 3.3.0
Build-Jdk-Spec: 22

缺失以下关键属性

  • Main-Class: org.springframework.boot.loader.JarLauncher
    (Spring Boot 的启动入口)
  • Start-Class: com.example.your.MainApplication
    (你的项目主类)

**2. 根本原因**

+ 你使用的是 `maven-jar-plugin`(普通 JAR 打包),而非 `spring-boot-maven-plugin`(Spring Boot 可执行 JAR 打包)。 + 普通 JAR 无法自动识别 Spring Boot 的启动层级。

**3. 解决方案**

**方法1:使用 Spring Boot 插件重新打包**(推荐)
1. 在 `pom.xml` 中添加插件:

xml

复制

下载

运行

<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>3.1.0</version> <!-- 与你的Spring Boot版本一致 --></plugin></plugins>
</build>
  1. 重新打包:

cmd

复制

下载

mvn clean package

  1. 验证新生成的 JAR:

cmd

复制

下载

jar tf target/ngpos-boot3-1.0.jar | findstr META-INF/MANIFEST.MF

输出应包含 Main-ClassStart-Class

**方法2:手动修复现有 JAR**
1. 解压 JAR:

cmd

复制

下载

jar xf ngpos-boot3-1.0.jar

  1. 编辑 META-INF/MANIFEST.MF,添加:

plaintext

复制

下载

Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.example.your.MainApplication
  1. 重新打包:

cmd

复制

下载

jar cfm0 ngpos-boot3-1.0-fixed.jar META-INF/MANIFEST.MF .

**方法3:临时运行(不修改 JAR)**
直接指定主类运行:

cmd

复制

下载

java -cp ngpos-boot3-1.0.jar com.example.your.MainApplication --server.port=8081


**4. 验证成功**

运行以下命令应正常启动:

cmd

复制

下载

java -jar target/ngpos-boot3-1.0.jar --server.port=8081


**5. 关键区别对比**

| **特性** | **普通 JAR (**`**maven-jar-plugin**`
**)** | **Spring Boot JAR (**`**spring-boot-maven-plugin**`
**)** | | --- | --- | --- | | `MANIFEST.MF` | 无 `Main-Class`
/`Start-Class` | 包含 Spring Boot 启动器 | | 依赖管理 | 依赖外置(需 `-cp`
指定) | 依赖内嵌在 `BOOT-INF/lib/` | | 可执行性 | 不可直接 `java -jar` | 可直接运行 |

**总结**

1. **必须使用**** **`**spring-boot-maven-plugin**` 打包 Spring Boot 项目。 2. 按上述方法修复后,`MANIFEST.MF` 将包含正确信息。 3. 如果问题依旧,检查项目结构是否完整(启动类必须在 `src/main/java` 下)。

<?xml version="1.0" encoding="UTF-8"?> 4.0.0 pos ngpos-boot3 1.0 <java.version>17</java.version> <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <spring-boot.version>3.2.0</spring-boot.version> <knife4j.springboot.version>4.4.0</knife4j.springboot.version> 3.0.3 <mysql-connector.version>8.0.29</mysql-connector.version> org.springframework.boot spring-boot-dependencies spring−boot.version</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><!−−引入SpringBootWeb−−><dependency><groupId>org.springframework.boot</groupId><artifactId>spring−boot−starter−web</artifactId></dependency><!−−引入SpringBootTest−−><dependency><groupId>org.springframework.boot</groupId><artifactId>spring−boot−starter−test</artifactId><scope>test</scope></dependency><!−−引入Mybatis−−><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis−spring−boot−starter</artifactId><version>{spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <!-- 引入 SpringBootWeb --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- 引入 SpringBootTest --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- 引入 Mybatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>springboot.version</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><!引入SpringBootWeb><dependency><groupId>org.springframework.boot</groupId><artifactId>springbootstarterweb</artifactId></dependency><!引入SpringBootTest><dependency><groupId>org.springframework.boot</groupId><artifactId>springbootstartertest</artifactId><scope>test</scope></dependency><!引入Mybatis><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatisspringbootstarter</artifactId><version>{mybatis-spring-boot} mysql mysql-connector-java mysql−connector.version</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutool−all</artifactId><version>5.8.0</version><!−−使用最新版本−−></dependency><!−−SpringDocOpenAPI(Swagger3.0+)−−><dependency><groupId>org.springdoc</groupId><artifactId>springdoc−openapi−starter−webmvc−ui</artifactId><version>2.5.0</version></dependency><dependency><groupId>io.swagger</groupId><artifactId>swagger−annotations</artifactId><version>1.5.20</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><scope>provided</scope></dependency><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelper−spring−boot−starter</artifactId><version>1.4.6</version></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven−compiler−plugin</artifactId><version>3.8.1</version><configuration><source>{mysql-connector.version}</version> </dependency> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.8.0</version> <!-- 使用最新版本 --> </dependency> <!-- SpringDoc OpenAPI (Swagger 3.0+) --> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> <version>2.5.0</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> <version>1.5.20</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.4.6</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>mysqlconnector.version</version></dependency><dependency><groupId>cn.hutool</groupId><artifactId>hutoolall</artifactId><version>5.8.0</version><!使用最新版本></dependency><!SpringDocOpenAPI(Swagger3.0+)><dependency><groupId>org.springdoc</groupId><artifactId>springdocopenapistarterwebmvcui</artifactId><version>2.5.0</version></dependency><dependency><groupId>io.swagger</groupId><artifactId>swaggerannotations</artifactId><version>1.5.20</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><scope>provided</scope></dependency><dependency><groupId>com.github.pagehelper</groupId><artifactId>pagehelperspringbootstarter</artifactId><version>1.4.6</version></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>mavencompilerplugin</artifactId><version>3.8.1</version><configuration><source>{maven.compiler.source} maven.compiler.target</target><encoding>{maven.compiler.target}</target> <encoding>maven.compiler.target</target><encoding>{project.build.sourceEncoding} org.springframework.boot spring-boot-maven-plugin ${spring-boot.version} com.example.dish.DishApplication true repackage repackage 这是我的pom文件

根据你的 pom.xml 文件,我发现导致 JAR 文件无法运行的关键问题是 **spring-boot-maven-plugin**** 配置中的 ****<skip>true</skip>**。这个参数会跳过 Spring Boot 的可执行 JAR 打包过程,导致生成的 JAR 文件缺少必要的启动信息。以下是完整的解决方案:


**1. 问题修复步骤**

**(解决方法)(1) 修改 **`**spring-boot-maven-plugin**`** 配置**
将以下部分:

xml

复制

下载

运行

<configuration><mainClass>com.example.dish.DishApplication</mainClass><skip>true</skip>  <!-- 删除这一行 -->
</configuration>

改为:

xml

复制

下载

运行

<configuration><mainClass>com.example.dish.DishApplication</mainClass>
</configuration>
**(2) 重新打包项目**
bash

复制

下载

mvn clean package

**(3) 验证生成的 JAR**
检查 `MANIFEST.MF` 是否包含关键属性:

bash

复制

下载

jar tf target/ngpos-boot3-1.0.jar | findstr META-INF/MANIFEST.MF

或直接解压查看:

bash

复制

下载

jar xf target/ngpos-boot3-1.0.jar META-INF/MANIFEST.MF
type META-INF\MANIFEST.MF

正常输出应包含

plaintext

复制

下载

Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.example.dish.DishApplication

**2. 其他优化建议**

**(1) 确保主类路径正确**
确认 `com.example.dish.DishApplication` 是你的 Spring Boot 主类,且包含 `@SpringBootApplication` 注解:

java

复制

下载

package com.example.dish;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class DishApplication {public static void main(String[] args) {SpringApplication.run(DishApplication.class, args);}
}
**(2) 检查依赖冲突**
你的 `pom.xml` 中混合了 Spring Boot 3.2.0 和部分非官方依赖(如 MyBatis Starter),建议统一版本管理:

xml

复制

下载

运行

<dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>3.0.3</version>  <!-- 与Spring Boot 3.2.0兼容 -->
</dependency>

(3) 清理无效配置

删除重复的 maven-compiler-plugin 版本声明(Spring Boot 已内置):

xml

复制

下载

运行

<!-- 可删除此插件,除非需要特殊配置 -->
<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version>  <!-- 删除这一行 -->
</plugin>

**3. 完整修复后的**** **`**pom.xml**`** ****关键部分**

xml

复制

下载

运行

<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>${spring-boot.version}</version><configuration><mainClass>com.example.dish.DishApplication</mainClass></configuration><executions><execution><id>repackage</id><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins>
</build>

**4. 重新运行项目**

bash

复制

下载

java -jar target/ngpos-boot3-1.0.jar --server.port=8081


**5. 常见问题排查**

| **问题现象** | **解决方案** | | | --- | --- | --- | | `ClassNotFoundException` | 检查 `Start-Class`
是否与主类全限定名一致 | | | 依赖冲突 | 运行 `mvn dependency:tree`
排查冲突 | | | 端口占用 | 使用 `netstat -ano | findstr 8081` 查找并终止占用进程 |

通过以上步骤,你的 Spring Boot 项目应该能正确打包为可执行 JAR 并运行。如果仍有问题,请提供完整的错误日志。

Error: connect ETIMEDOUT 8.138.207.62:8081 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16)怎么回事

这个错误 Error: connect ETIMEDOUT 8.138.207.62:8081 表示你的应用程序(可能是前端或客户端)无法连接到目标服务器** **8.138.207.62** **8081** **端口。以下是逐步排查和解决方案:


**1. 问题原因**

+ **服务器未启动**:后端服务未运行在 `8081` 端口。 + **防火墙/安全组拦截**:服务器防火墙或云平台安全组未放行 `8081` 端口。 + **网络不通**:IP 地址错误、服务器离线或网络路由问题。 + **后端绑定限制**:Spring Boot 默认只监听 `localhost`,需修改为 `0.0.0.0`。

**2. 逐步排查**

**步骤1:检查后端是否正常运行**
在服务器上执行:

bash

复制

下载

# 查看进程
ps aux | grep java# 检查端口监听
netstat -tulnp | grep 8081  # Linux
netstat -ano | findstr 8081 # Windows
  • 如果无输出,说明后端未启动,需重新运行:

bash

复制

下载

java -jar ngpos-boot3-1.0.jar --server.port=8081

**步骤2:验证服务器本地访问**
在服务器上测试:

bash

复制

下载

curl http://localhost:8081/api/health

  • 如果成功,说明服务已启动但外部无法访问。
  • 如果失败,检查后端日志:

bash

复制

下载

tail -f nohup.out # 或直接查看控制台输出

**步骤3:检查服务器防火墙**
+ **Linux**:

bash

复制

下载

sudo ufw status          # Ubuntu
sudo firewall-cmd --list-ports  # CentOS

开放端口:

bash

复制

下载

sudo ufw allow 8081/tcp

  • Windows

powershell

复制

下载

netsh advfirewall firewall add rule name=“Open 8081” dir=in action=allow protocol=TCP localport=8081

**步骤4:检查云平台安全组**
+ **阿里云/腾讯云/AWS**:登录控制台,确保安全组规则允许 `8081` 端口的入站流量(来源设为 `0.0.0.0/0` 或你的IP)。
**步骤5:修改后端绑定地址**
如果后端只监听 `127.0.0.1`,需修改为 `0.0.0.0`:
  • application.properties 或启动命令中指定:

properties

复制

下载

server.address=0.0.0.0

或:

bash

复制

下载

java -jar ngpos-boot3-1.0.jar --server.port=8081 --server.address=0.0.0.0

**步骤6:检查IP和网络**
+ 确认 `8.138.207.62` 是服务器的**公网IP**(而非内网IP)。 + 从本地测试网络连通性:

bash

复制

下载

ping 8.138.207.62          # 检查是否可达
telnet 8.138.207.62 8081   # 检查端口是否开放(Windows需启用Telnet客户端)
- 如果 `ping` 通但 `telnet` 失败,说明端口未开放。
- 如果 `ping` 不通,可能是IP错误或服务器离线。

**3. 前端配置修正**

如果前端代码中硬编码了 `8.138.207.62:8081`,确保:
  1. 后端已正确部署到该地址。
  2. 前端请求的URL与后端一致(如 http://8.138.207.62:8081/api/data)。

**4. 常见问题总结**

| **现象** | **解决方案** | | --- | --- | | 后端未启动 | 运行 `java -jar`
并检查日志 | | 端口被防火墙拦截 | 开放服务器防火墙和云平台安全组 | | 后端绑定到 `localhost` | 添加 `--server.address=0.0.0.0` | | IP地址错误 | 确认服务器公网IP |

**5. 最终验证**

1. 在服务器本地测试:

bash

复制

下载

curl http://localhost:8081/api/health

  1. 从其他机器测试:

bash

复制

下载

curl http://8.138.207.62:8081/api/health

如果仍失败,请提供以下信息:

  • 后端启动日志。
  • netstat 端口监听结果。
  • 云平台安全组规则截图。

Windows执行curl http://localhost:8081/ticket/listAll C:\Users\Administrator>curl http://localhost:8081/ticket/listAll {“timestamp”:“2025-05-05T01:40:30.424+00:00”,“status”:500,“error”:“Internal Server Error”,“path”:“/ticket/listAll”}

这个错误 500 Internal Server Error 表示后端服务虽然已启动,但在处理 /ticket/listAll 请求时发生了服务器内部异常。以下是逐步排查和解决方案:


**1. 查看后端详细日志**

在运行后端服务的终端或日志文件中查找错误堆栈(关键步骤!):

bash

复制

下载

# 如果使用 nohup 启动
tail -f nohup.out# 如果直接运行 jar
java -jar ngpos-boot3-1.0.jar --server.port=8081

重点关注以下信息

  • 异常类型(如 NullPointerExceptionSQLException)。
  • 报错的具体代码行(如 com.example.controller.TicketController:45)。

**2. 常见原因及修复**

**(1) 数据库连接失败**
+ **现象**:日志中出现 `Connection refused` 或 `Access denied`。 + **解决**:1. 检查 `application.properties` 中的数据库配置:

properties

复制

下载

spring.datasource.url=jdbc:mysql://localhost:3306/your_db?useSSL=false
spring.datasource.username=root
spring.datasource.password=your_password
2. 确保 MySQL 服务已启动:

bash

复制

下载

net start mysql # Windows

**(2) SQL 查询错误**
+ **现象**:日志中有 `SQLSyntaxErrorException` 或 `Table not found`。 + **解决**:- 检查 `listAll` 接口对应的 SQL(如 MyBatis 的 XML 或注解)。- 确认数据库表名和字段名是否匹配(区分大小写)。
**(3) 空指针异常(NullPointerException)**
+ **现象**:日志显示某行代码尝试调用 `null` 对象的方法。 + **解决**:- 检查 `TicketController` 中 `listAll()` 方法的逻辑。- 确保依赖的 Service 或 Repository 已正确注入(如 `@Autowired`)。
**(4) 依赖缺失**
+ **现象**:`ClassNotFoundException` 或 `NoSuchBeanDefinitionException`。 + **解决**:- 检查 `pom.xml` 是否缺少依赖(如 MyBatis、MySQL 驱动)。- 重新打包并确保依赖被包含:

bash

复制

下载

mvn clean package


**3. 本地快速测试**

**(1) 直接访问数据库**
用 MySQL 客户端执行 `listAll` 接口对应的 SQL,验证查询是否正常:

sql

复制

下载

SELECT * FROM ticket; – 替换为实际查询

**(2) 使用 Postman 测试接口**
发送 GET 请求到 `http://localhost:8081/ticket/listAll`,查看原始响应:


**4. 代码层检查**

**(1) 确认 Controller 代码**
检查 `TicketController` 是否类似如下结构:

java

复制

下载

@RestController
@RequestMapping("/ticket")
public class TicketController {@Autowiredprivate TicketService ticketService;@GetMapping("/listAll")public List<Ticket> listAll() {return ticketService.listAll(); // 确保此方法实现正确}
}
**(2) 检查 Service/Repository 层**
确保 `TicketService` 和 `TicketRepository` 的方法实现无逻辑错误。

**5. 临时解决方案**

如果急需接口响应,可添加错误处理:

java

复制

下载

@GetMapping("/listAll")
public ResponseEntity<?> listAll() {try {return ResponseEntity.ok(ticketService.listAll());} catch (Exception e) {return ResponseEntity.status(500).body("Error: " + e.getMessage());}
}

**6. 最终验证**

修复后重新打包并运行:

bash

复制

下载

mvn clean package
java -jar target/ngpos-boot3-1.0.jar --server.port=8081

再次访问 http://localhost:8081/ticket/listAll,应返回 200 OK 和数据列表。


**附:常见错误日志示例**

1. **数据库连接失败**:

复制

下载

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure

  1. SQL 错误

复制

下载

java.sql.SQLSyntaxErrorException: Table ‘your_db.ticket’ doesn’t exist

  1. 空指针异常

复制

下载

java.lang.NullPointerException: null
at com.example.TicketService.listAll(TicketService.java:25)

请根据实际日志调整修复策略!

2025-05-05T09:47:42.095+08:00 ERROR 2428 — [nio-8081-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.mybatis.spring.MyBatisSystemException] with root cause 发送 GET 请求到 http://localhost:8081/ticket/listAll,查看原始响应:不成功

根据错误日志和你的描述,问题出在 MyBatis 数据库操作层MyBatisSystemException),导致 /ticket/listAll 接口请求失败。以下是完整的排查和解决方案:


**1. 错误分析**

关键日志:

log

复制

下载

ERROR o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] threw exception 
[Request processing failed: org.mybatis.spring.MyBatisSystemException]

根本原因

  • MyBatis 执行 SQL 时发生异常(如 SQL 语法错误、数据库连接问题、结果映射失败等)。
  • 需要进一步查看 完整堆栈日志 定位具体原因。

**2. 获取完整错误日志**

在启动命令中添加日志级别参数,打印详细错误:

bash

复制

下载

java -jar ngpos-boot3-1.0.jar --server.port=8081 --logging.level.root=DEBUG

或检查日志文件(如 nohup.out),找到类似以下内容:

log

复制

下载

Caused by: org.apache.ibatis.exceptions.PersistenceException: 
Error querying database. Cause: java.sql.SQLException: Table 'your_db.ticket' doesn't exist

**3. 常见原因及修复**

**(1) 数据库表不存在**
+ **现象**:日志中有 `Table 'xxx.ticket' doesn't exist`。 + **解决**:1. 登录 MySQL 确认表是否存在:

sql

复制

下载

USE your_db;
SHOW TABLES LIKE 'ticket';
2. 如果表不存在,执行建表 SQL:

sql

复制

下载

CREATE TABLE ticket (id INT PRIMARY KEY AUTO_INCREMENT,-- 其他字段...
);
**(2) SQL 语法错误**
+ **现象**:日志中有 `SQLSyntaxErrorException`。 + **解决**: 检查 MyBatis 的 XML 或注解中的 SQL:

xml

复制

下载

运行

<!-- 示例:Mapper XML -->
<select id="listAll" resultType="com.example.model.Ticket">SELECT * FROM ticket  -- 确保表名和字段正确
</select>
**(3) 数据库连接失败**
+ **现象**:日志中有 `CommunicationsException` 或 `Access denied`。 + **解决**:1. 检查 `application.properties`:

properties

复制

下载

spring.datasource.url=jdbc:mysql://localhost:3306/your_db?useSSL=false
spring.datasource.username=your_user
spring.datasource.password=your_password
2. 测试数据库连接:

bash

复制

下载

mysql -u your_user -p your_db -e “SELECT 1”

**(4) 结果映射失败**
+ **现象**:日志中有 `ResultMap` 或字段映射错误。 + **解决**: 确保 `Ticket` 类的字段与数据库列名一致:

java

复制

下载

public class Ticket {private Integer id;  // 必须与数据库列名匹配(或通过 @Column 注解指定)// getter/setter...
}

**4. 本地快速验证**

**(1) 直接执行 SQL**
在 MySQL 客户端运行 `listAll` 对应的 SQL:

sql

复制

下载

USE your_db;
SELECT * FROM ticket;  -- 替换为实际查询
**(2) 测试 MyBatis Mapper**
在单元测试中直接调用 Mapper:

java

复制

下载

@SpringBootTest
public class TicketMapperTest {@Autowiredprivate TicketMapper ticketMapper;@Testvoid testListAll() {List<Ticket> tickets = ticketMapper.listAll();assertNotNull(tickets);}
}

**5. 修复后重新部署**

1. 修改代码后重新打包:

bash

复制

下载

mvn clean package

  1. 启动服务:

bash

复制

下载

java -jar target/ngpos-boot3-1.0.jar --server.port=8081

  1. 再次测试接口:

bash

复制

下载

curl http://localhost:8081/ticket/listAll


**6. 备用方案**

如果问题仍未解决,在 Controller 中添加临时日志:

java

复制

下载

@GetMapping("/listAll")
public List<Ticket> listAll() {try {return ticketService.listAll();} catch (Exception e) {e.printStackTrace();  // 打印异常到控制台throw e;}
}

**附:MyBatis 常见错误对照表**

| **错误日志** | **解决方案** | | --- | --- | | `Table 'xxx.ticket' doesn't exist` | 检查数据库表是否存在 | | `Column 'id' not found` | 检查实体类与数据库字段映射 | | `Communications link failure` | 检查数据库连接配置 | | `Invalid bound statement (not found)` | 检查 Mapper XML 文件路径 |

请根据实际日志选择对应方案!

2025-05-05T09:52:20.092+08:00 INFO 1324 — [ main] com.example.dish.DishApplication : Started DishApplication in 56.986 seconds (process running for 59.099) 2025-05-05T09:52:20.144+08:00 DEBUG 1324 — [ main] o.s.b.a.ApplicationAvailabilityBean : Application availability state LivenessState changed to CORRECT 2025-05-05T09:52:20.155+08:00 DEBUG 1324 — [ main] o.s.b.a.ApplicationAvailabilityBean : Application availability state ReadinessState changed to ACCEPTING_TRAFFIC 2025-05-05T09:52:52.486+08:00 DEBUG 1324 — [alina-utility-1] o.apache.catalina.session.ManagerBase : Start expire sessions StandardManager at 1746409972478 sessioncount 0 2025-05-05T09:52:52.497+08:00 DEBUG 1324 — [alina-utility-1] o.apache.catalina.session.ManagerBase : End expire sessions StandardManager processingTime 19 expired sessions: 0 2025-05-05T09:53:52.522+08:00 DEBUG 1324 — [alina-utility-2] o.apache.catalina.session.ManagerBase : Start expire sessions StandardManager at 1746410032522 sessioncount 0 2025-05-05T09:53:52.611+08:00 DEBUG 1324 — [alina-utility-2] o.apache.catalina.session.ManagerBase : End expire sessions StandardManager processingTime 89 expired sessions: 0这是成功了吗

从你提供的日志来看,Spring Boot 应用已经成功启动,但 /ticket/listAll 接口的 500 错误表明业务逻辑或数据库操作存在问题。以下是详细分析:


**1. 日志解读(成功部分)**

log

复制

下载

2025-05-05T09:52:20.092+08:00 INFO 1324 — [ main] com.example.dish.DishApplication : Started DishApplication in 56.986 seconds

  • 应用启动成功:Spring Boot 已完成初始化,耗时约 57 秒。
  • 健康状态正常

log

复制

下载

LivenessState changed to CORRECT
ReadinessState changed to ACCEPTING_TRAFFIC

表示应用已就绪,可接收外部请求。


**2. 问题定位(**`**/ticket/listAll**`** ****500 错误)**

虽然服务启动成功,但接口报错 `500 Internal Server Error`,说明 **MyBatis 操作数据库时抛出了异常**。 需要进一步检查:
**(1) 查看完整错误堆栈**
在启动命令中添加调试参数,捕获 MyBatis 异常详情:

bash

复制

下载

java -jar ngpos-boot3-1.0.jar --server.port=8081 --logging.level.org.mybatis=DEBUG

或直接检查日志文件(如 nohup.out),找到类似以下内容:

log

复制

下载

Caused by: org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database. Cause: java.sql.SQLSyntaxErrorException: Table 'your_db.ticket' doesn't exist
**(2) 常见原因
| **错误现象** | **解决方案** | | --- | --- | | **表不存在** | 执行 `SHOW TABLES`
确认表是否存在,或运行建表 SQL | | **SQL 语法错误** | 检查 MyBatis Mapper 中的 SQL 语句 | | **数据库连接失败** | 验证 `application.properties`
的数据库配置 | | **字段映射失败** | 确保实体类属性与数据库列名一致 |

**3. 快速验证步骤**

**(1) 直接测试数据库连接**
bash

复制

下载

mysql -u your_db_user -p your_db_name -e “SELECT * FROM ticket LIMIT 1;”

  • 如果报错 Table doesn't exist,需建表:

sql

复制

下载

CREATE TABLE ticket (id INT PRIMARY KEY AUTO_INCREMENT,-- 其他字段...
);
**(2) 检查 MyBatis Mapper**
确认 `TicketMapper.xml` 或注解中的 SQL 正确:

xml

复制

下载

运行

<select id="listAll" resultType="com.example.model.Ticket">SELECT * FROM ticket  <!-- 确保表名正确 -->
</select>
**(3) 验证实体类映射**
确保 `Ticket` 类的字段与数据库列匹配:

java

复制

下载

public class Ticket {private Integer id;  // 必须与数据库列名一致// getter/setter...
}

**4. 修复后重启测试**

1. 修改代码后重新打包:

bash

复制

下载

mvn clean package

  1. 启动服务:

bash

复制

下载

java -jar target/ngpos-boot3-1.0.jar --server.port=8081

  1. 测试接口:

bash

复制

下载

curl http://localhost:8081/ticket/listAll


**5. 关键结论**

+ ✅ **服务启动成功**:日志显示应用已正常启动。 + ❗ **接口逻辑异常**:需修复 MyBatis 数据库操作问题。 + 🔍 **下一步**:检查 **完整错误堆栈** 或按上述方案逐步排查。

2025-05-05T09:56:08.522+08:00 DEBUG 1324 — [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost] : Processing ErrorPage[errorCode=0, location=/error] 2025-05-05T09:56:08.571+08:00 DEBUG 1324 — [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : “ERROR” dispatch for GET “/error”, parameters={} 2025-05-05T09:56:08.578+08:00 DEBUG 1324 — [nio-8081-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController#error(HttpServletRequest) 2025-05-05T09:56:08.682+08:00 DEBUG 1324 — [nio-8081-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Using ‘application/json’, given [/] and supported [application/json, application/*+json] 2025-05-05T09:56:08.690+08:00 DEBUG 1324 — [nio-8081-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [{timestamp=Mon May 05 09:56:08 CST 2025, status=500, error=Internal Server Error, path=/ticket/listA (truncated)…] 2025-05-05T09:56:08.934+08:00 DEBUG 1324 — [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : Exiting from “ERROR” dispatch, status 500 2025-05-05T09:56:08.952+08:00 DEBUG 1324 — [nio-8081-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Disabling the response for further output 2025-05-05T09:56:08.983+08:00 DEBUG 1324 — [nio-8081-exec-1] o.apache.coyote.http11.Http11Processor : Socket: [org.apache.tomcat.util.net.NioEndpointNioSocketWrapper@707bfe88:org.apache.tomcat.util.net.NioChannel@43b7230f:java.nio.channels.SocketChannel[connectedlocal=/[0:0:0:0:0:0:0:1]:8081remote=/[0:0:0:0:0:0:0:1]:50068]],Statusin:[OPENREAD],Stateout:[CLOSED]2025−05−05T09:56:09.034+08:00DEBUG1324−−−[nio−8081−exec−1]o.apache.tomcat.util.threads.LimitLatch:Countingdown[http−nio−8081−exec−1]latch=12025−05−05T09:56:09.075+08:00DEBUG1324−−−[nio−8081−exec−1]org.apache.tomcat.util.net.NioEndpoint:Calling[org.apache.tomcat.util.net.NioEndpoint@7e1c69fa].closeSocket([org.apache.tomcat.util.net.NioEndpointNioSocketWrapper@707bfe88:org.apache.tomcat.util.net.NioChannel@43b7230f:java.nio.channels.SocketChannel[connected local=/[0:0:0:0:0:0:0:1]:8081 remote=/[0:0:0:0:0:0:0:1]:50068]], Status in: [OPEN_READ], State out: [CLOSED] 2025-05-05T09:56:09.034+08:00 DEBUG 1324 --- [nio-8081-exec-1] o.apache.tomcat.util.threads.LimitLatch : Counting down[http-nio-8081-exec-1] latch=1 2025-05-05T09:56:09.075+08:00 DEBUG 1324 --- [nio-8081-exec-1] org.apache.tomcat.util.net.NioEndpoint : Calling [org.apache.tomcat.util.net.NioEndpoint@7e1c69fa].closeSocket([org.apache.tomcat.util.net.NioEndpointNioSocketWrapper@707bfe88:org.apache.tomcat.util.net.NioChannel@43b7230f:java.nio.channels.SocketChannel[connectedlocal=/[0:0:0:0:0:0:0:1]:8081remote=/[0:0:0:0:0:0:0:1]:50068]],Statusin:[OPENREAD],Stateout:[CLOSED]20250505T09:56:09.034+08:00DEBUG1324[nio8081exec1]o.apache.tomcat.util.threads.LimitLatch:Countingdown[httpnio8081exec1]latch=120250505T09:56:09.075+08:00DEBUG1324[nio8081exec1]org.apache.tomcat.util.net.NioEndpoint:Calling[org.apache.tomcat.util.net.NioEndpoint@7e1c69fa].closeSocket([org.apache.tomcat.util.net.NioEndpointNioSocketWrapper@707bfe88:org.apache.tomcat.util.net.NioChannel@43b7230f:java.nio.channels.SocketChannel[connected local=/[0:0:0:0:0:0:0:1]:8081 remote=/[0:0:0:0:0:0:0:1]:50068]])

根据日志分析,你的Spring Boot应用已成功启动,但在访问 /ticket/listAll 接口时发生了500错误。以下是详细的问题诊断和解决方案:

1. 问题诊断

日志显示以下关键信息:
  1. 应用启动成功(Started DishApplication
  2. 接口请求触发了错误处理(Processing ErrorPage[errorCode=0, location=/error]
  3. 最终返回了500错误(status=500, error=Internal Server Error

2. 可能原因

根据日志中没有直接显示具体异常,但结合之前的错误,最可能的原因是:
  • MyBatis数据库操作异常
  • 数据库连接问题
  • SQL查询错误
  • 实体类映射问题

3. 解决方案

第一步:获取完整错误信息
在application.properties中添加:

properties

复制

下载

server.error.include-message=always
server.error.include-stacktrace=always
第二步:检查数据库配置
确保你的application.properties中包含正确的数据库配置:

properties

复制

下载

spring.datasource.url=jdbc:mysql://localhost:3306/your_database?useSSL=false
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
第三步:验证数据库连接
1. 确认MySQL服务正在运行 2. 使用MySQL客户端测试连接:

bash

复制

下载

mysql -u your_username -p your_database

第四步:检查Ticket表
1. 确认表是否存在:

sql

复制

下载

USE your_database;
SHOW TABLES LIKE 'ticket';
  1. 如果表不存在,创建表:

sql

复制

下载

CREATE TABLE ticket (id INT PRIMARY KEY AUTO_INCREMENT,-- 添加其他必要字段
);
第五步:检查MyBatis映射
1. 确认Mapper接口:

java

复制

下载

@Mapper
public interface TicketMapper {@Select("SELECT * FROM ticket")List<Ticket> listAll();
}
  1. 确认实体类:

java

复制

下载

public class Ticket {private Integer id;// 其他字段和getter/setter
}
第六步:添加异常处理
在Controller中添加详细日志:

java

复制

下载

@RestController
@RequestMapping("/ticket")
public class TicketController {private static final Logger logger = LoggerFactory.getLogger(TicketController.class);@Autowiredprivate TicketService ticketService;@GetMapping("/listAll")public ResponseEntity<?> listAll() {try {return ResponseEntity.ok(ticketService.listAll());} catch (Exception e) {logger.error("获取ticket列表失败", e);return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("获取数据失败: " + e.getMessage());}}
}

4. 验证步骤

1. 重启应用:

bash

复制

下载

mvn spring-boot:run

  1. 再次访问接口:

bash

复制

下载

curl http://localhost:8081/ticket/listAll

  1. 检查应用日志获取完整错误信息

5. 常见问题排查表

| **现象** | **可能原因** | **解决方案** | | --- | --- | --- | | 表不存在 | 数据库未初始化 | 执行建表SQL | | 连接被拒绝 | 数据库配置错误 | 检查application.properties | | 字段不匹配 | 实体类与表结构不一致 | 同步实体类和表结构 | | SQL语法错误 | Mapper中的SQL有问题 | 检查Mapper XML或注解 |

请按照以上步骤排查,如果问题仍然存在,请提供完整的错误堆栈信息,我可以帮你进一步分析。

如果我的后端是在服务器上运行,MYSQL也在服务器上,需要改成公网地址吗

是否需要将 MySQL 连接地址改为公网 IP,取决于你的 网络架构安全需求。以下是详细分析和建议:


**1. 不同场景下的配置方案**

**场景1:后端和MySQL在同一台服务器**
**推荐配置**:使用 `localhost` 或 `127.0.0.1`(无需公网IP)
  • properties复制下载spring.datasource.url=jdbc:mysql://localhost:3306/your_db?useSSL=false
    • 优点:速度快,不经过外部网络,最安全。
    • 缺点:仅限本机访问。
**场景2:后端和MySQL在同一内网(不同服务器)**
+ **推荐配置**:使用内网IP(如 `192.168.1.100`)

properties

复制

下载

spring.datasource.url=jdbc:mysql://192.168.1.100:3306/your_db?useSSL=false

- **优点**:内网通信,速度快且安全。
- **缺点**:需确保服务器间内网互通。
**场景3:后端需通过公网访问MySQL**
+ **配置**:使用公网IP(如 `8.138.207.62`)

properties

复制

下载

spring.datasource.url=jdbc:mysql://8.138.207.62:3306/your_db?useSSL=false

- **优点**:可从任何地方连接。
- **缺点**:**高风险**!需额外安全措施。

**2. 公网访问MySQL的安全风险**

如果必须使用公网IP,**务必**采取以下措施:
  1. 限制访问IP
    在MySQL配置中只允许后端服务器的公网IP连接:

sql

复制

下载

CREATE USER ‘your_user’@‘后端服务器公网IP’ IDENTIFIED BY ‘password’;

  1. 启用SSL加密
    在JDBC URL中添加参数:

properties

复制

下载

spring.datasource.url=jdbc:mysql://8.138.207.62:3306/your_db?useSSL=true&requireSSL=true

  1. 修改MySQL默认端口
    避免使用默认的 3306 端口(如改为 33060)。
  2. 设置复杂密码
    避免使用弱密码(如 root/123456)。

**3. 最佳实践建议**

1. **优先使用内网连接**- 如果后端和MySQL在同一机房或VPC内,永远使用内网IP。- 云服务器(如阿里云ECS和RDS)通常提供内网域名(如 `rm-xxx.mysql.rds.aliyuncs.com`)。 2. **使用SSH隧道(安全替代方案)** 如果必须从外部访问,通过SSH隧道连接(无需暴露MySQL端口):

bash

复制

下载

# 在本地建立隧道(将服务器3306端口映射到本地33306)
ssh -L 33306:localhost:3306 user@服务器公网IP

然后连接 jdbc:mysql://localhost:33306/your_db

  1. VPN/专线网络
    企业级场景下,使用VPN或专线连接数据库服务器。

**4. 配置示例**

**安全的内网连接配置(推荐)**
properties

复制

下载

# application.properties
spring.datasource.url=jdbc:mysql://192.168.1.100:3306/your_db?useSSL=false
spring.datasource.username=db_user
spring.datasource.password=StrongPassword@123
**公网连接配置(需谨慎)**
properties

复制

下载

# application.properties
spring.datasource.url=jdbc:mysql://8.138.207.62:33060/your_db?useSSL=true&requireSSL=true
spring.datasource.username=db_user
spring.datasource.password=StrongPassword@123

**5. 检查MySQL网络配置**

1. 登录MySQL服务器,检查绑定地址:

sql

复制

下载

SHOW VARIABLES LIKE ‘bind_address’;

- 如果为 `127.0.0.1`,则只允许本地连接。
- 如需允许远程连接,改为 `0.0.0.0`(需在 `my.cnf` 中配置)。
  1. 开放防火墙端口:

bash

复制

下载

# Linux
sudo ufw allow 33060/tcp# Windows
netsh advfirewall firewall add rule name="MySQL" dir=in action=allow protocol=TCP localport=33060

**总结**

| **场景** | **配置方案** | **安全等级** | | --- | --- | --- | | 后端和MySQL同机 | `localhost` | ★★★★★ | | 后端和MySQL同内网 | 内网IP | ★★★★☆ | | 必须公网访问 | 公网IP+SSL+IP白名单 | ★★☆☆☆ |

强烈建议:除非绝对必要,否则不要将MySQL暴露在公网!优先使用内网或SSH隧道。

本回答由 AI 生成,内容仅供参考,请仔细甄别。

后端在服务器运行成功,可以查到数据,但是前端在本地出现错误10:08:17 [vite] http proxy error: /kitchen/tasks Error: connect ETIMEDOUT 8.138.207.62:8081 at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1605:16) (x24)

这个错误表明你的 本地前端无法连接到后端服务器的公网IP(**8.138.207.62:8081**。以下是逐步排查和解决方案:


**1. 检查后端服务是否真正可访问**

**(1) 在服务器本地测试**
bash

复制

下载

curl http://localhost:8081/kitchen/tasks

  • 如果成功,说明后端服务正常运行。
  • 如果失败,检查后端日志:

bash

复制

下载

journalctl -u your-service --no-pager -n 50  # Linux系统日志
或直接查看 nohup.out
**(2) 从其他机器测试**
在另一台电脑或手机(非本地开发机)上测试:

bash

复制

下载

curl http://8.138.207.62:8081/kitchen/tasks

  • 如果失败,说明服务器未开放公网访问。

**2. 确保服务器开放了公网访问**

**(1) 检查后端绑定地址**
确保 Spring Boot 绑定到 `0.0.0.0` 而非 `127.0.0.1`:

properties

复制

下载

# application.properties
server.address=0.0.0.0
server.port=8081

或启动时指定:

bash

复制

下载

java -jar your-app.jar --server.address=0.0.0.0 --server.port=8081

**(2) 检查防火墙**
+ **Linux**:

bash

复制

下载

sudo ufw status  # 查看防火墙状态
sudo ufw allow 8081/tcp
  • Windows

powershell

复制

下载

netsh advfirewall firewall add rule name=“Open 8081” dir=in action=allow protocol=TCP localport=8081

**(3) 检查云服务器安全组**
+ 登录云平台(阿里云/腾讯云/AWS等),确保安全组规则允许 `8081` 端口的入站流量(来源IP设为 `0.0.0.0/0` 或你的本地IP)。

**3. 前端配置修正**

**(1) 检查代理配置**
如果使用 Vite 开发服务器,确保 `vite.config.js` 的代理配置正确:

js

复制

下载

export default defineConfig({server: {proxy: {'/kitchen': {target: 'http://8.138.207.62:8081',  // 确保此处是后端公网IPchangeOrigin: true,secure: false,rewrite: (path) => path.replace(/^\/kitchen/, '')}}}
})
**(2) 直接测试后端接口**
在浏览器中直接访问,验证是否能连通:

复制

下载

http://8.138.207.62:8081/kitchen/tasks

  • 如果浏览器能访问但前端代码不能,说明是 前端代理配置问题
  • 如果浏览器也不能访问,说明是 网络/后端问题

**4. 网络诊断工具**

**(1) 测试端口连通性**
从本地电脑执行:

bash

复制

下载

telnet 8.138.207.62 8081  # Windows需启用Telnet客户端
或
nc -zv 8.138.207.62 8081  # Linux/Mac
  • 如果超时,说明网络不通(防火墙/安全组/后端未监听公网)。
  • 如果连接成功,说明前端代码或代理配置有问题。
**(2) 检查本地网络限制**
+ 公司网络可能屏蔽了非标准端口(如8081),尝试改用 `443` 或 `80` 端口。 + 本地防火墙可能拦截请求,临时关闭测试:

powershell

复制

下载

netsh advfirewall set allprofiles state off  # Windows
sudo ufw disable  # Linux

**5. 替代方案(如果无法开放公网IP)**

**(1) 使用内网穿透工具**
+ **Ngrok**(临时测试):

bash

复制

下载

ngrok http 8081 # 会生成一个公网URL如 https://abc123.ngrok.io

前端配置代理到 https://abc123.ngrok.io

  • frp(长期使用):
    在服务器和本地搭建内网穿透通道。
**(2) 将前端也部署到服务器**
+ 将打包后的前端代码(如 `dist` 文件夹)放到服务器的 Nginx 目录下,通过域名访问。

**6. 常见问题总结**

| **现象** | **解决方案** | | --- | --- | | 后端本地可访问,公网超时 | 检查 `server.address=0.0.0.0`
和安全组规则 | | 前端代理配置错误 | 修正 `vite.config.js`
的 `target`
地址 | | 公司网络限制 | 改用 HTTPS 端口(443)或联系网络管理员 | | 云服务器未绑定公网IP | 在云平台分配公网IP并绑定到实例 |

**最终验证**

1. 在服务器本地:

bash

复制

下载

curl http://localhost:8081/kitchen/tasks

  1. 从本地电脑:

bash

复制

下载

curl http://8.138.207.62:8081/kitchen/tasks

  1. 如果以上都成功,前端问题一定是 代理配置错误浏览器缓存(尝试无痕窗口)。

按照以上步骤逐步排查,问题应该能解决!如果仍有疑问,请提供:

  1. 后端启动日志(包含 server.address 信息)
  2. vite.config.js 完整内容
  3. curl http://8.138.207.62:8081/kitchen/tasks 的响应结果

本地浏览器不能访问http://8.138.207.62:8081/kitchen/tasks,但是服务器上输入localhost可以访问

这个问题表明你的 后端服务没有正确绑定到公网IP服务器防火墙/安全组阻止了外部访问。以下是详细解决方案:


**1. 检查后端服务绑定地址**

**(1) 确认Spring Boot监听所有IP**
在服务器上运行:

bash

复制

下载

netstat -tulnp | grep 8081  # Linux
netstat -ano | findstr 8081 # Windows
  • 正常输出应显示0.0.0.0:8081:::8081
  • 如果显示** ****127.0.0.1:8081**:说明后端仅监听本地,需修改配置:

application.properties 中添加:

properties

复制

下载

server.address=0.0.0.0

或启动时指定:

bash

复制

下载

java -jar your-app.jar --server.address=0.0.0.0 --server.port=8081

**(2) 验证后端日志**
检查启动日志中是否有以下内容:

log

复制

下载

Tomcat initialized with port(s): 8081 (http)


**2. 检查服务器防火墙**

**(1) Linux服务器**
bash

复制

下载

# 查看防火墙状态
sudo ufw status# 开放8081端口
sudo ufw allow 8081/tcp
sudo ufw reload
**(2) Windows服务器**
powershell

复制

下载

# 开放端口
netsh advfirewall firewall add rule name="SpringBoot" dir=in action=allow protocol=TCP localport=8081

**3. 检查云服务器安全组规则**

+ **登录云平台**(阿里云/腾讯云/AWS等),找到安全组配置。 + **添加入站规则**:- 端口范围:`8081`- 授权对象:`0.0.0.0/0`(或你的本地公网IP)- 协议:TCP

**4. 测试公网连通性**

**(1) 从本地电脑测试**
bash

复制

下载

telnet 8.138.207.62 8081 # Windows需启用Telnet功能

  • 如果连接失败:说明网络层被拦截(防火墙/安全组/ISP限制)。
  • 如果连接成功但无响应:后端未正确处理请求。
**(2) 使用在线工具检测**
访问 [端口检测工具](https://www.yougetsignal.com/tools/open-ports/) 输入 `8.138.207.62` 和 `8081`,检查端口是否开放。

**5. 其他可能原因**

**(1) ISP屏蔽了非标准端口**
+ 尝试改用 `80` 或 `443` 端口(需root权限):

bash

复制

下载

java -jar your-app.jar --server.port=80

**(2) 本地网络限制**
+ 切换网络(如手机热点)测试。 + 联系公司IT确认是否屏蔽了 `8081` 端口。

**6. 临时解决方案(快速验证)**

**(1) 使用SSH隧道**
在本地电脑执行:

bash

复制

下载

ssh -L 8081:localhost:8081 user@8.138.207.62

然后访问:

复制

下载

http://localhost:8081/kitchen/tasks

**(2) 使用Ngrok内网穿透**
在服务器运行:

bash

复制

下载

ngrok http 8081

前端访问Ngrok提供的域名(如 https://abc123.ngrok.io/kitchen/tasks)。


**验证流程图**

图表

代码

下载


**总结**

| **步骤** | **检查项** | **命令/操作** | | --- | --- | --- | | 1 | 后端绑定地址 | `netstat -tulnp | grep 8081` | | 2 | 防火墙规则 | `sudo ufw allow 8081/tcp` | | 3 | 云安全组 | 控制台添加规则 | | 4 | 本地网络限制 | 切换网络测试 | | 5 | 临时解决方案 | SSH隧道/Ngrok |

按照以上步骤操作后,问题应该能解决。如果仍有疑问,请提供:

  1. netstat -tulnp | grep 8081 的输出
  2. 云平台安全组规则的截图
  3. 后端启动日志(包含端口绑定信息)

C:\Windows\System32>telnet 8.138.207.62 8081 ‘telnet’ 不是内部或外部命令,也不是可运行的程序 或批处理文件。

在 Windows 系统中,telnet 命令默认未启用,需要手动安装。以下是详细解决方案:


**1. 启用 Windows Telnet 客户端**

**方法1:通过控制面板**
1. 打开 **控制面板** > **程序** > **启用或关闭 Windows 功能**。 2. 勾选 **Telnet 客户端**,点击 **确定**。
**方法2:通过命令行(管理员权限)**
cmd

复制

下载

dism /online /Enable-Feature /FeatureName:TelnetClient

重启命令提示符后即可使用。


**2. 使用替代工具测试端口**

如果不想启用 Telnet,可以用以下工具替代:
**(1) PowerShell 的**** **`**Test-NetConnection**`
powershell

复制

下载

Test-NetConnection 8.138.207.62 -Port 8081

  • 成功输出示例

powershell

复制

下载

ComputerName     : 8.138.207.62
RemotePort       : 8081
InterfaceAlias   : Ethernet
SourceAddress    : 192.168.1.100
TcpTestSucceeded : True  # 表示端口可访问
**(2)**** **`**curl**`** ****测试**
如果已安装 Git Bash 或 WSL:

bash

复制

下载

curl -v http://8.138.207.62:8081/kitchen/tasks

  • 如果返回 HTTP 响应(如 200 OK),说明端口开放且服务正常。
  • 如果超时或无响应,说明网络不通。
**(3) 在线端口检测工具**
访问 [Port Checker](https://www.portcheckers.com/) 或 [YouGetSignal](https://www.yougetsignal.com/tools/open-ports/),输入 IP 和端口检测。

**3. 关键排查步骤**

**(1) 确认后端服务已绑定公网IP**
在服务器运行:

bash

复制

下载

netstat -ano | findstr 8081

  • 正确输出

bash

复制

下载

TCP 0.0.0.0:8081 0.0.0.0:0 LISTENING

如果显示 127.0.0.1:8081,需修改 Spring Boot 配置:

properties

复制

下载

server.address=0.0.0.0

**(2) 检查防火墙**
在服务器上开放端口:
  • Windows

powershell

复制

下载

netsh advfirewall firewall add rule name=“Open 8081” dir=in action=allow protocol=TCP localport=8081

  • Linux

bash

复制

下载

sudo ufw allow 8081/tcp

**(3) 验证云服务器安全组**
+ 登录云平台控制台(阿里云/腾讯云等),检查安全组是否允许 `8081` 端口的入站流量。

**4. 常见问题解决**

| **现象** | **解决方案** | | --- | --- | | `TcpTestSucceeded: False` | 检查防火墙/安全组,确保后端绑定到 `0.0.0.0` | | `Connection refused` | 后端服务未运行或端口错误 | | 超时无响应 | 网络路由问题,尝试更换本地网络 |

**5. 快速验证**

1. **在服务器本地测试**:

bash

复制

下载

curl http://localhost:8081/kitchen/tasks

  1. 从其他设备(如手机)访问

复制

下载

http://8.138.207.62:8081/kitchen/tasks

- 如果手机能访问但电脑不能,可能是本地网络限制。

完成以上步骤后,你应该能确定是 网络问题 还是 后端配置问题。如果仍有疑问,请提供 Test-NetConnectioncurl 的输出结果。

PS C:\WINDOWS\system32> Test-NetConnection 8.138.207.62 -Port 8081 警告: TCP connect to (8.138.207.62 : 8081) failed ComputerName : 8.138.207.62 RemoteAddress : 8.138.207.62 RemotePort : 8081 InterfaceAlias : WLAN SourceAddress : 192.168.3.65 PingSucceeded : True PingReplyDetails (RTT) : 16 ms TcpTestSucceeded : False

根据 Test-NetConnection 的测试结果,你的本地电脑可以 Ping 通服务器PingSucceeded: True),但 无法连接 8081 端口TcpTestSucceeded: False)。以下是逐步排查和解决方案:


**1. 问题定位**

+ ✅ **网络层正常**:能 Ping 通服务器(延迟 16ms),说明 IP 可达。 + ❌ **端口层失败**:8081 端口被拦截或后端未监听公网。

**2. 服务器端排查**

**(1) 检查后端是否监听公网IP**
在服务器上运行:

bash

复制

下载

# Linux
netstat -tulnp | grep 8081# Windows
netstat -ano | findstr 8081
  • 正常输出应包含
    0.0.0.0:8081:::8081
  • 如果显示** ****127.0.0.1:8081**
    需修改 Spring Boot 配置:

properties

复制

下载

# application.properties
server.address=0.0.0.0
**(2) 检查服务器防火墙**
+ **Linux**:

bash

复制

下载

sudo ufw status          # 查看状态
sudo ufw allow 8081/tcp  # 开放端口
  • Windows

powershell

复制

下载

netsh advfirewall firewall add rule name=“Open 8081” dir=in action=allow protocol=TCP localport=8081

**(3) 检查云平台安全组**
+ 登录云服务器控制台(阿里云/腾讯云等),确保安全组规则允许 `8081` 端口的 **入站流量**(来源IP设为 `0.0.0.0/0` 或你的本地公网IP)。

**3. 本地网络排查**

**(1) 尝试关闭本地防火墙**
临时关闭防火墙测试:

powershell

复制

下载

netsh advfirewall set allprofiles state off

测试后记得重新启用:

powershell

复制

下载

netsh advfirewall set allprofiles state on

**(2) 切换网络测试**
+ 尝试用手机热点或其他网络访问 `http://8.138.207.62:8081/kitchen/tasks`。 + 如果手机能访问,说明当前本地网络(如公司/学校)可能屏蔽了 `8081` 端口。

**4. 临时解决方案**

**(1) 使用SSH隧道(推荐)**
在本地电脑运行:

bash

复制

下载

ssh -L 8081:localhost:8081 username@8.138.207.62

然后访问:

复制

下载

http://localhost:8081/kitchen/tasks

**(2) 改用常见端口**
如果 `8081` 被屏蔽,尝试改用 `80` 或 `443` 端口:

bash

复制

下载

java -jar your-app.jar --server.port=80

前端代理配置同步修改:

js

复制

下载

// vite.config.js
proxy: {'/kitchen': {target: 'http://8.138.207.62:80',  // 改为新端口// ...}
}

**5. 验证流程图**

图表

代码

下载


**总结**

| **步骤** | **操作** | **预期结果** | | --- | --- | --- | | 1 | 服务器 `netstat` | 确认监听 `0.0.0.0:8081` | | 2 | 开放防火墙端口 | Linux: `ufw allow 8081` | | 3 | 检查云安全组 | 允许入站 `8081/TCP` | | 4 | 本地关闭防火墙测试 | 排除本地网络限制 | | 5 | 改用SSH隧道 | 绕过端口屏蔽 |

如果完成所有步骤仍无法解决,请提供:

  1. 服务器的 netstat -ano | findstr 8081 输出
  2. 云平台安全组规则的截图
  3. 后端启动日志(含端口绑定信息)

image.png

PNG 223.5KB

C:\Users\Administrator>netstat -ano | findstr 8081 TCP 0.0.0.0:8081 0.0.0.0:0 LISTENING 5632 TCP [::]:8081 [::]:0 LISTENING 5632 C:\Users\Administrator>java -jar C:\Users\Administrator\Desktop\ngpos-boot3-1.0.jar --server.address=0.0.0.0 --server.port=8081 . ____ _ __ _ _ /\ / __ _ () __ __ _ \ \ \ \ ( ( )__ | '_ | '| | ’ / ` | \ \ \ \ \/ )| |)| | | | | || (| | ) ) ) ) ’ || .__|| ||| |_, | / / / / =========||==============|/=//// :: Spring Boot :: (v3.2.0) 2025-05-05T10:10:00.756+08:00 INFO 5632 — [ main] com.example.dish.DishApplication : Starting DishApplication using Java 24 with PID 5632 (C:\Users\Administrator\Desktop\ngpos-boot3-1.0.jar started by Administrator in C:\Users\Administrator) 2025-05-05T10:10:00.764+08:00 INFO 5632 — [ main] com.example.dish.DishApplication : No active profile set, falling back to 1 default profile: “default” WARNING: A restricted method in java.lang.System has been called WARNING: java.lang.System::load has been called by org.apache.tomcat.jni.Library in an unnamed module (jar:nested:/C:/Users/Administrator/Desktop/ngpos-boot3-1.0.jar/!BOOT-INF/lib/tomcat-embed-core-10.1.16.jar!/) WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module WARNING: Restricted methods will be blocked in a future release unless native access is enabled 2025-05-05T10:10:08.154+08:00 INFO 5632 — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8081 (http) 2025-05-05T10:10:08.216+08:00 INFO 5632 — [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2025-05-05T10:10:08.221+08:00 INFO 5632 — [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.16] 2025-05-05T10:10:08.457+08:00 INFO 5632 — [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2025-05-05T10:10:08.462+08:00 INFO 5632 — [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 7282 ms 2025-05-05T10:10:15.864+08:00 INFO 5632 — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8081 (http) with context path ‘’ 2025-05-05T10:10:15.979+08:00 INFO 5632 — [ main] com.example.dish.DishApplication : Started DishApplication in 17.849 seconds (process running for 20.032) 2025-05-05T10:10:16.831+08:00 INFO 5632 — [0.0-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet ‘dispatcherServlet’ 2025-05-05T10:10:16.845+08:00 INFO 5632 — [0.0-8081-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet ‘dispatcherServlet’ 2025-05-05T10:10:16.848+08:00 INFO 5632 — [0.0-8081-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 3 ms 2025-05-05T10:10:17.101+08:00 INFO 5632 — [0.0-8081-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting… 2025-05-05T10:10:19.078+08:00 INFO 5632 — [0.0-8081-exec-1] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@531bbd16 2025-05-05T10:10:19.107+08:00 INFO 5632 — [0.0-8081-exec-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.

根据你提供的信息,问题已经明确:安全组规则配置错误。以下是具体分析和解决方案:


**1. 问题确认**

✅ **后端服务已正确启动** 日志显示 Tomcat 已监听 `0.0.0.0:8081`:
  • log复制下载Tomcat started on port 8081 (http) with context path ‘’
  • 本地网络可通
    Test-NetConnection 显示 Ping 成功(延迟 16ms)。
  • 安全组规则错误
    当前安全组中 8081 端口的规则未生效,原因如下:
    • 规则优先级为 1,但已有同优先级规则(如8080、3306等)可能冲突。
    • 规则描述显示为 后端,但未明确是否已启用(截图中的复选框未勾选)。

**2. 解决方案**

**(1) 修改安全组规则**
在云平台控制台执行以下操作:
  1. 删除现有 8081 端口规则(避免优先级冲突)。
  2. 新增一条独立规则
    • 授权策略:允许
    • 优先级:设为更高优先级(如 100
    • 协议类型:自定义 TCP
    • 端口范围:8081/8081
    • 访问来源:0.0.0.0/0
    • 描述:Spring Boot 后端服务
**(2) 验证规则生效**
在服务器本地运行:

bash

复制

下载

telnet localhost 8081  # 确保服务正常

从其他机器测试:

bash

复制

下载

telnet 8.138.207.62 8081
  • 如果仍失败,可能是云平台网络ACL或其他安全策略拦截。
**(3) 临时测试(关闭防火墙)**
在服务器上临时关闭防火墙测试:
  • Windows

powershell

复制

下载

netsh advfirewall set allprofiles state off
  • Linux

bash

复制

下载

sudo ufw disable

测试后记得重新启用防火墙。


**3. 其他可能性排查**

**(1) 云平台网络ACL**
+ 检查是否配置了网络ACL(比安全组优先级更高),需单独放行8081端口。
**(2) 后端服务绑定问题**
虽然日志显示监听 `0.0.0.0`,但仍需确认:

bash

复制

下载

netstat -ano | findstr 8081
  • 确保输出包含:
    TCP 0.0.0.0:8081 0.0.0.0:0 LISTENING
**(3) 本地网络限制**
+ 尝试用手机热点访问 `http://8.138.207.62:8081/kitchen/tasks`,排除公司/家庭网络限制。

**4. 配置示例(安全组规则)**

| **字段** | **值** | | --- | --- | | 授权策略 | 允许 | | 优先级 | 100 | | 协议类型 | 自定义 TCP | | 端口范围 | 8081 | | 访问来源 | 0.0.0.0/0 | | 描述 | Spring Boot 服务 |

**5. 最终验证**

1. **在服务器本地测试**:

bash

复制

下载

curl http://localhost:8081/kitchen/tasks
  1. 从公网测试

bash

复制

下载

curl http://8.138.207.62:8081/kitchen/tasks

○ 如果返回数据,说明问题已解决。

○ 如果仍超时,联系云服务商检查底层网络。


**总结**

| **步骤** | **操作** | **预期结果** | | --- | --- | --- | | 1 | 修正安全组规则 | 8081 端口允许入站 | | 2 | 验证端口连通性 | `telnet 8.138.207.62 8081`
成功 | | 3 | 检查网络ACL | 确保无额外拦截 | | 4 | 本地网络测试 | 切换网络环境验证 |

按以上步骤操作后,你的前端应能正常访问后端接口。如果仍有问题,请提供:

  1. 更新后的安全组规则截图
  2. 从其他网络(如手机4G)测试 curl 的结果

image.png

PNG 208.18KB

PS C:\WINDOWS\system32> Test-NetConnection 8.138.207.62 -Port 8081 警告: TCP connect to (8.138.207.62 : 8081) failed ComputerName : 8.138.207.62 RemoteAddress : 8.138.207.62 RemotePort : 8081 InterfaceAlias : WLAN SourceAddress : 192.168.3.65 PingSucceeded : True PingReplyDetails (RTT) : 12 ms

根据最新信息,问题已明确:安全组规则已正确配置(8081端口优先级2),但端口仍无法连通。以下是终极解决方案:


**1. 问题根源**

+ ✅ **安全组已配置**:8081端口规则优先级为2,允许所有IP访问(0.0.0.0/0)。 + ✅ **后端监听正常**:`netstat`显示服务绑定到`0.0.0.0:8081`。 + ❌ **端口仍不通**:`Test-NetConnection`失败,说明流量被拦截在**网络ACL或服务器防火墙**层。

**2. 终极解决步骤**

**(1) 检查服务器防火墙(关键!)**
在Windows服务器上执行:

powershell

复制

下载

# 查看现有规则
Get-NetFirewallRule -DisplayName "8081" | Format-Table -AutoSize# 开放8081端口(如果不存在规则)
New-NetFirewallRule -DisplayName "Allow8081" -Direction Inbound -LocalPort 8081 -Protocol TCP -Action Allow
**(2) 验证云平台网络ACL**
+ 登录云控制台,找到**网络ACL**(非安全组),确保有规则放行8081端口:

复制

下载

入方向:允许 源IP 0.0.0.0/0 目标端口8081

  • 阿里云路径:专有网络VPC > 网络ACL > 入方向规则
**(3) 检查本地网络限制**
+ 尝试用**手机热点**访问:

bash

复制

下载

curl http://8.138.207.62:8081/kitchen/tasks

如果手机能访问,说明当前网络(如公司WiFi)屏蔽了8081端口。

**(4) 更换服务端口测试**
临时改用80端口(需管理员权限):

bash

复制

下载

java -jar ngpos-boot3-1.0.jar --server.port=80

然后在安全组中开放80端口测试。


**3. 快速诊断命令**

在服务器上运行以下命令,直接验证公网访问:

powershell

复制

下载

# 监听8081端口的进程ID
$pid = (Get-NetTCPConnection -LocalPort 8081).OwningProcess# 确认进程身份(应为SYSTEM或你的用户)
Get-Process -Id $pid | Select-Object ProcessName, UserName

**4. 备用解决方案**

如果仍无法解决,使用以下方式绕过限制:
**(1) SSH隧道端口转发**
bash

复制

下载

ssh -L 8081:localhost:8081 username@8.138.207.62

前端访问http://localhost:8081

**(2) 内网穿透工具**
bash

复制

下载

# 服务器运行(生成临时公网URL)
ngrok http 8081

**5. 最终检查表**

| **层级** | **检查项** | **验证方式** | | --- | --- | --- | | **安全组** | 8081端口规则优先级>1 | 控制台截图确认 | | **网络ACL** | 入方向允许8081 | 云平台检查 | | **服务器防火墙** | 入站规则放行8081 | `Get-NetFirewallRule` | | **本地网络** | 切换手机热点测试 | `curl`
或浏览器访问 |

**结论**

1. **90%概率是Windows防火墙拦截**,运行以下命令后问题应解决:
New-NetFirewallRule -DisplayName "SpringBoot8081" -Direction Inbound -LocalPort 8081 -Protocol TCP -Action Allow
  1. 如果仍失败,请联系云服务商检查底层网络策略

C:\Users\Administrator>Get-NetFirewallRule -DisplayName “8081” | Format-Table -AutoSize ‘Get-NetFirewallRule’ 不是内部或外部命令,也不是可运行的程序 或批处理文件。

这个错误表明你的 Windows 系统缺少 PowerShell 的 NetSecurity 模块(通常出现在 Windows Server 精简版或旧版本中)。以下是完整的解决方案:


**1. 替代方法检查防火墙规则**

**(1) 使用基础命令查看防火墙状态**
cmd

复制

下载

netsh advfirewall show allprofiles
  • 检查 State 是否为 ON
**(2) 查看现有入站规则**
cmd

复制

下载

netsh advfirewall firewall show rule name=all dir=in | findstr "8081"
  • 如果无输出,说明没有针对 8081 端口的规则。

**2. 手动开放 8081 端口**

**(1) 通过命令添加规则**
cmd

复制

下载

netsh advfirewall firewall add rule name="SpringBoot 8081" dir=in action=allow protocol=TCP localport=8081
**(2) 验证规则是否生效**
cmd

复制

下载

netsh advfirewall firewall show rule name="SpringBoot 8081"
  • 确认输出中包含 Enabled: YesAction: Allow

**3. 其他可能性排查**

**(1) 检查云平台网络ACL**
+ 登录云控制台,确认 **网络ACL**(非安全组)是否放行 8081 端口:

复制

下载

入方向:源 0.0.0.0/0,目标端口 8081,允许

**(2) 临时关闭防火墙测试**
cmd

复制

下载

netsh advfirewall set allprofiles state off
  • 测试后务必重新启用

cmd

复制

下载

netsh advfirewall set allprofiles state on

**4. 验证端口连通性**

在本地电脑重新测试:

powershell

复制

下载

Test-NetConnection 8.138.207.62 -Port 8081
  • 如果 TcpTestSucceeded: True,问题已解决。
  • 如果仍失败,联系云服务商检查底层网络。

**5. 总结命令清单**

| **操作** | **命令** | | --- | --- | | 查看防火墙状态 | `netsh advfirewall show allprofiles` | | 添加8081端口规则 | `netsh advfirewall firewall add rule name="SpringBoot 8081" dir=in action=allow protocol=TCP localport=8081` | | 验证规则 | `netsh advfirewall firewall show rule name="SpringBoot 8081"` | | 临时关闭防火墙 | `netsh advfirewall set allprofiles state off` |

完成以上步骤后,你的 8081 端口应该可以正常访问。如果仍有问题,请提供:

  1. netsh advfirewall show allprofiles 的输出
  2. 云平台 网络ACL 规则的截图

PS C:\Users\Administrator> Get-NetFirewallRule -DisplayName “8081” | Format-Table -AutoSize Get-NetFirewallRule : 找不到任何“DisplayName”属性等于“8081”的 MSFT_NetFirewallRule 对象。请验证属性值,然后重试。 所在位置 行:1 字符: 1 + Get-NetFirewallRule -DisplayName “8081” | Format-Table -AutoSize + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (8081:String) [Get-NetFirewallRule], CimJobException + FullyQualifiedErrorId : CmdletizationQuery_NotFound_DisplayName,Get-NetFirewallRule

根据错误信息,您的 Windows 防火墙中尚未创建针对 8081 端口的规则。以下是完整的解决方案:

1. 创建新的防火墙规则(管理员权限运行)

powershell

复制

下载

New-NetFirewallRule -DisplayName "Allow_TCP_8081" -Direction Inbound -Protocol TCP -LocalPort 8081 -Action Allow

2. 验证规则是否生效

powershell

复制

下载

Get-NetFirewallRule -DisplayName "Allow_TCP_8081" | Format-Table Name,Enabled,Action,Direction,Protocol,LocalPort -AutoSize

3. 备选方案(如果仍无法创建)

方法一:使用传统防火墙界面
1. 打开"高级安全 Windows 防火墙" 2. 右键"入站规则" → "新建规则" 3. 选择"端口" → "TCP/8081" → "允许连接" → 全选配置文件 → 命名"Allow_TCP_8081"
方法二:使用netsh命令
cmd

复制

下载

netsh advfirewall firewall add rule name="Allow_TCP_8081" dir=in action=allow protocol=TCP localport=8081

4. 验证端口可访问性

在服务器上测试:

powershell

复制

下载

Test-NetConnection -ComputerName localhost -Port 8081

5. 最终检查清单

1. 确认规则已创建且启用:

powershell

复制

下载

Get-NetFirewallRule -DisplayName "Allow_TCP_8081" | Select-Object Name,Enabled,Action
  1. 确认服务正在监听:

cmd

复制

下载

netstat -ano | findstr 8081
  1. 从外部测试:

powershell

复制

下载

Test-NetConnection -ComputerName 8.138.207.62 -Port 8081

如果仍然失败,请检查:

  • 云服务商的安全组规则
  • 网络ACL设置
  • 服务器上其他安全软件(如第三方防火墙)的拦截情况

防火墙规则生效,服务器端口可访问,确认规则已创建且启用,确认服务正在监听,外部测试失败 PS C:\WINDOWS\system32> Test-NetConnection -ComputerName 8.138.207.62 -Port 8081 警告: TCP connect to (8.138.207.62 : 8081) failed ComputerName : 8.138.207.62 RemoteAddress : 8.138.207.62 RemotePort : 8081 InterfaceAlias : WLAN SourceAddress : 192.168.3.65 PingSucceeded : True PingReplyDetails (RTT) : 325 ms TcpTestSucceeded : False

根据您提供的信息,虽然服务器本地的防火墙规则和端口监听都已正确配置,但外部访问仍然失败。这通常意味着问题出在云服务商的网络层。以下是系统化的解决方案:


**终极排查步骤**

**1. 确认云服务商安全组配置**
+ 登录云控制台,检查安全组规则:- 确保有**入方向**规则允许TCP 8081端口(源IP:`0.0.0.0/0`)- 检查规则优先级(确保没有更高优先级的拒绝规则)
**2. 检查网络ACL(关键!)**
+ 在云平台找到**网络ACL**(与安全组不同):- 路径示例:`专有网络VPC > 网络ACL > 入方向规则`- 确保有规则放行8081端口(优先级高于拒绝规则)
**3. 验证服务器绑定地址**
在服务器上运行:

powershell

复制

下载

netstat -ano | findstr 8081

  • 正确输出应包含:
    TCP 0.0.0.0:8081 0.0.0.0:0 LISTENING
**4. 云服务商特殊限制**
+ 某些云平台(如阿里云)的**ECS实例**需额外检查:- 实例详情页的"安全组"和"弹性网卡"配置- 是否有"基础防护"或"DDoS防护"拦截了端口
**5. 跨网络测试**
+ 通过手机热点或其他网络访问:

powershell

复制

下载

# 在手机连接的电脑上测试
Test-NetConnection 8.138.207.62 -Port 8081

如果手机网络能通,说明当前本地网络有问题。


**临时解决方案**

如果急需使用,可选择以下方式:
**(1) 端口映射(绕过限制)**
powershell

复制

下载

# 在服务器上将80端口映射到8081(需管理员权限)
netsh interface portproxy add v4tov4 listenport=80 connectport=8081

然后通过http://8.138.207.62:80访问。

**(2) 使用Cloudflare Tunnel**
bash

复制

下载

# 在服务器安装并运行
cloudflared tunnel --url http://localhost:8081

**排查流程图**

![](https://i-blog.csdnimg.cn/img_convert/d22efe21305aac5030bdfff810316e06.png)

**各云平台检查路径**

| **云服务商** | **安全组路径** | **网络ACL路径** | | --- | --- | --- | | 阿里云 | ECS实例 > 安全组 | 专有网络VPC > 网络ACL | | 腾讯云 | 云服务器 > 安全组 | 私有网络 > 网络ACL | | AWS | EC2 > Security Groups | VPC > Network ACLs |

**最终建议**

1. **提交工单**:将以下信息提供给云服务商:- 实例ID/公网IP- `netstat -ano`和`Test-NetConnection`结果- 安全组/ACL配置截图 2. **更换默认端口**:将服务改为80/443端口测试(需管理员权限):

powershell

复制

下载

java -jar your-app.jar --server.port=80

如果完成所有步骤仍无法解决,很可能是云平台底层网络限制,需联系技术支持进一步排查。

PS C:\Users\Administrator> # 在服务器上将80端口映射到8081(需管理员权限) >> netsh interface portproxy add v4tov4 listenport=80 connectport=8081 一个或多个重要的参数没有输入。 请验证需要的参数,然后再次输入。 此命令提供的语法不正确。请查看帮助以获取正确的语法信息。 用法: add v4tov4 [listenport=]| [connectaddress=]| [[connectport=]|] [[listenaddress=]|] [[protocol=]tcp] 参数: 标记 值 listenport - IPv4 侦听端口。 connectaddress - IPv4 连接地址。 connectport - IPv4 连接端口。 listenaddress - IPv4 侦听地址。 protocol - 使用的协议。现在只支持 TCP。 说明: 添加通过 IPv4 的 IPv4 和代理连接到的侦听项目。

感谢您提供详细的错误信息。以下是修正后的完整端口映射命令和详细说明:

1. 正确的端口映射命令(管理员权限运行)

cmd

复制

下载

netsh interface portproxy add v4tov4 listenport=80 listenaddress=0.0.0.0 connectport=8081 connectaddress=127.0.0.1 protocol=tcp

2. 命令参数说明

| **参数** | **值** | **说明** | | --- | --- | --- | | `listenport` | 80 | 外部访问的端口 | | `listenaddress` | 0.0.0.0 | 监听所有网络接口 | | `connectport` | 8081 | 内部服务实际端口 | | `connectaddress` | 127.0.0.1 | 转发到本机 | | `protocol` | tcp | 使用TCP协议 |

3. 验证映射是否成功

cmd

复制

下载

netsh interface portproxy show all

预期输出:

复制

下载

侦听 ipv4:                 连接到 ipv4:地址            端口        地址            端口
--------------- ----------  --------------- ----------
0.0.0.0         80          127.0.0.1       8081

4. 开放防火墙80端口(如果尚未开放)

cmd

复制

下载

netsh advfirewall firewall add rule name=“HTTP_80” dir=in action=allow protocol=TCP localport=80

5. 测试访问

现在可以通过以下方式访问:

复制

下载

http://8.138.207.62:80/kitchen/tasks

6. 注意事项

1. 需要以管理员身份运行CMD/PowerShell 2. 如果80端口被系统服务占用,可改用其他端口(如8080):

cmd

复制

下载

netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=8081 connectaddress=127.0.0.1

  1. 重启后映射会失效,如需持久化可以创建计划任务

7. 完整操作示例

cmd

复制

下载

:: 添加端口映射
netsh interface portproxy add v4tov4 listenport=80 listenaddress=0.0.0.0 connectport=8081 connectaddress=127.0.0.1:: 查看所有映射规则
netsh interface portproxy show all:: 开放防火墙
netsh advfirewall firewall add rule name="HTTP_80" dir=in action=allow protocol=TCP localport=80:: 测试映射是否生效(在服务器本地执行)
curl http://localhost:80/kitchen/tasks

如果仍然遇到问题,可能是:

  1. IIS或其他服务占用了80端口(使用netstat -ano | findstr :80检查)
  2. 云服务商限制了80端口(需在控制台开放)
  3. 本地网络屏蔽了80端口(尝试手机热点访问)

================================================================

是的,前端 Vue 项目只需修改 vite.config.js 中的代理目标地址,将其指向后端服务器的公网 IP 或域名即可访问后端数据。以下是具体操作和注意事项:


**1. 修改 Vite 代理配置**

在 `vite.config.js` 中更新 `proxy` 配置,将目标地址改为后端服务器的公网 IP 和端口(例如 `http://8.138.207.62:8081`):
// vite.config.js
export default defineConfig({server: {proxy: {'/api': {  // 代理所有以 /api 开头的请求target: 'http://8.138.207.62:8081',  // 后端服务器地址changeOrigin: true,                  // 允许跨域rewrite: (path) => path.replace(/^\/api/, '')  // 可选:重写路径}}}
})

**2. 前端代码中的请求地址**

确保前端代码中的请求路径 **以 **`/api`** 开头**(与代理配置匹配),例如:
axios.get('/api/kitchen/tasks')  // 会被代理到 http://8.138.207.62:8081/kitchen/tasks

**3. 关键注意事项**

**(1) 后端跨域配置**
如果前端直接访问后端地址(不通过 Vite 代理),需在后端启用跨域支持:
  • Spring Boot 配置
@Configuration
public class CorsConfig implements WebMvcConfigurer {@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**").allowedOrigins("*")  // 或指定前端域名.allowedMethods("GET", "POST");}
}
**(2) 生产环境部署**
+ **Vite 代理仅用于开发环境**。生产环境下需:1. 将前端代码打包后部署到 Nginx/Apache。2. 在 Nginx 中配置反向代理:
location /api {proxy_pass http://8.138.207.62:8081;proxy_set_header Host $host;
}
**(3) 网络连通性验证**
+ **测试代理是否生效**:
curl http://localhost:5173/api/kitchen/tasks  # 开发环境前端地址

应返回后端数据。

  • 检查服务器防火墙/安全组
    确保后端服务器的 8081 端口对前端部署的 IP 开放(参考之前的安全组配置)。

**4. 完整流程示例**

**开发环境**
1. 修改 `vite.config.js`:
proxy: {'/api': {target: 'http://8.138.207.62:8081',changeOrigin: true,}
}
  1. 启动前端开发服务器:
npm run dev
  1. 访问 http://localhost:5173,所有 /api 请求会自动转发到后端。
**生产环境**
1. 打包前端代码:
npm run build
  1. 部署到 Nginx,并添加代理配置:
server {listen 80;server_name your-domain.com;location / {root /path/to/dist;index index.html;}location /api {proxy_pass http://8.138.207.62:8081;}
}

**5. 常见问题排查**

| 问题现象 | 解决方案 | | --- | --- | | 前端请求 404 | 检查 `vite.config.js` 的 `target` 和 `rewrite` 配置 | | 跨域错误(CORS) | 确保后端配置了跨域或通过代理转发 | | 连接超时 | 验证后端 IP 和端口是否可从前端网络访问 | | 生产环境代理失败 | 检查 Nginx 配置和日志(`/var/log/nginx/error.log`) |

**总结**

+ **开发环境**:只需修改 `vite.config.js` 的 `proxy.target`。 + **生产环境**:需通过 Nginx/Apache 配置反向代理。 + **关键检查点**:网络连通性、跨域配置、路径匹配。

完成以上步骤后,前端即可正确访问后端数据!

http://www.dtcms.com/a/442785.html

相关文章:

  • 嵌入式linux内核驱动学习4——LED
  • 建设银行人力资源招聘网站建筑行业教育培训平台
  • 蚌埠网站制作网站开发好找工作吗
  • Spring Boot 整合 MyBatis
  • 【C++实战(70)】C++ 跨平台开发:CMake构建实战指南
  • algorithm <B> data manipulation in huffman algorithm 4/99
  • 三网合一网站建设福建省建设执业资格注册中心网站
  • Rokid JSAR 技术开发全指南+实战演练
  • 昆明做网站哪家便宜计算机网络课程设计
  • 《网页设计与网站建设》A卷答案成都o2o网站建设
  • 建筑工程网官网入口商丘seo教程
  • 求解子网掩码
  • 网站 转成 微信小程序西城上海网站建设
  • 【AI论文】SLA:通过精细可调的稀疏线性注意力机制突破扩散变换器中的稀疏性局限
  • 博客自定义网站服饰 视频 网站建设
  • SSM创新实践学分管理系统08a30(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
  • 太原建设网站制作WordPress手机号验证登录
  • SSM大学教务管理系统61dy9(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
  • 连云港市建设工程安全监督站网站青岛平台网站建设
  • 缓存锁(Cache Lock)是什么?
  • linux建设网站php打开提示404申请一个域名可以建设一个网站吗
  • 人工智能开发工具全景指南:从编码辅助到模型部署的全链路实践
  • 做一个宣传网站要多少钱wordpress 要加上
  • mysql学习
  • 爬坑 10 年!爱回收询价接口实战:从型号匹配、分页续传到数据完整性校验
  • 人工智能领域、图欧科技、IMYAI智能助手2025年9月更新月报
  • 怎么利用网站开发app中海园林建设有限公司网站
  • Python Access:删除数据库中指定的表和查询
  • 苏州设计网页网站珠宝行业做网站的好处
  • 设备管理系统网站模板什么网站比较容易做