问题 - 本地主机的“404 错误”:8081/question/allQuestions

问题描述 投票:0回答:3

应用属性:

# 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

postman picture result

我尝试执行上面的程序..但是我对@Getmapping和@PostMapping都遇到了相同的错误

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

控制器: QuestionController

enter image description here 它在终端上没有显示任何错误...我仍然没有得到所需的输出

java spring-boot spring-restcontroller
3个回答
1
投票

getAllQuestions() 的路径已使用

/allQuestions
定义,但您使用
/allQuestion
API 路径调用 API。


1
投票

尝试检查您的控制器以调查 404 错误的原因。当您的应用程序无法在控制器中找到请求的资源(例如 /question/allQuestion 端点)时,通常会发生该错误。


0
投票

您是否在控制器中正确注册了路径?

例如:

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

    @GetMapping(path = "/allQuestion")
    ResponseEntity<?> getAllQuestions() {
        return ResponseEntity.ok();
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.