You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

访问localhost:8081/question/allQuestions出现404 Not Found错误排查求助

访问localhost:8081/question/allQuestions出现404 Not Found错误排查求助

大家好,我在运行Spring Boot项目时碰到了一个棘手的问题——访问localhost:8081/question/allQuestions时一直返回404 Not Found错误,不管是GET还是POST请求都出现同样的情况,而且控制台完全没有报错信息,Postman里也只显示404,实在不知道哪里出问题了,想请大家帮忙排查一下。

我的application.properties配置

# Database Connection Properties
spring.datasource.url=jdbc:mysql://localhost:3306/quizmaker
spring.datasource.username=root
spring.datasource.password=Corona@123

# Specify the JDBC driver for MySQL
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# Hibernate properties
spring.jpa.hibernate.ddl-auto=update

# # Connection pool settings
# spring.datasource.hikari.connection-timeout=20000
# spring.datasource.hikari.minimum-idle=5
# spring.datasource.hikari.maximum-pool-size=20
# spring.datasource.hikari.idle-timeout=300000

# Logging SQL statements
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

server.port=8081

我的QuestionController代码

@RestController
@RequestMapping(path = "/question")
public class QuestionController{

private QuestionService questionService;

public QuestionController (QuestionService questionService)
{
this.questionService = questionService;
}

// ------Read Operation----
@GetMapping(path = "/allQuestions")
public List<com.example.model.Question> getAllQuestions () {
return questionService.getAllQuestions();
}

@GetMapping(path = "/category/{category}")
public List<com.example.model.Question> getQuestionsByCategory (@PathVariable String category) {
return questionService.getQuestionsByCategory( category);
}

//------Create Operation---
@PostMapping(path = "/create")
public String createQuestion (@RequestBody Question question) {
return questionService.createQuestion ((com.example.model.Question) question);
}

}

Postman返回的错误信息

{"timestamp":"2024-02-11T11:22:56.192+00:00",
"status":404,
"error":"Not Found",
"path":"/question/allQuestions"}

我确认过项目运行端口确实是8081,请求路径也没写错,但就是访问不到对应的接口,控制台也没有任何异常日志输出,实在摸不着头绪,有没有大佬能帮我分析下可能的原因?

备注:内容来源于stack exchange,提问作者Deepa Lakshmi.l

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 06:13:07