Ubuntu环境下Swagger的常见错误及解决方法
try_files指令)、启动用户无权限读取Swagger文件、防火墙阻止端口访问。try_files $uri $uri/ /index.html;(解决前端路由问题);www-data,运行chown -R www-data:www-data /path/to/swagger/files赋予读取权限;sudo ufw allow 8080(默认端口)允许HTTP访问。Failed to load API definition、NoSuchMethodError或ClassNotFoundException。swagger.json/swagger.yaml文件路径配置错误、Swagger与Spring Boot/JDK版本不兼容。application.properties/application.yml中springdoc.swagger-ui.path或swagger.configuration.file指向正确路径;EACCES: permission denied(如mkdir /usr/local/lib/node_modules/swagger失败)、无法读取Swagger文件。sudo chown -R $(whoami) ~/.npm ~/.nvm,避免使用sudo安装全局包;chmod -R 755 /path/to/swagger。npm ERR! code ERESOLVE(依赖冲突)、Cannot find module 'xxx'(依赖缺失)。spring.mvc.pathmatch.matching-strategy=ant_path_matcher禁用新版本路径匹配策略;node_modules目录和package-lock.json,运行npm install重新安装。Port 3000 is already in use、同局域网其他设备无法访问。swagger-editor -p 4000);lsof -i :3000查找占用进程,运行kill -9 <PID>终止;sudo ufw allow 3000允许端口访问。java.lang.NullPointerException、Failed to execute fetch(请求方法错误)。@EnableOpenApi注解缺失)、接口请求方式与@RequestBody注解不匹配(GET请求带请求体)。@Configuration和@EnableOpenApi注解;@RequestBody,将请求方式改为POST。