使用 PathVariable 的 SpringBoot3 迁移未将其显示为参数,当调用完成时抛出 500 内部服务器错误

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

我们将 Spring Boot 2.7.15 应用程序迁移到 3.2.1。我们更新了 pom.xml 以反映所有 3.2.1 特定依赖项

在 Spring Boot 3.2.1 迁移之后,注意到对于任何

@GetMapping
包括
@PathVariable
当发出请求时,我们收到 500 内部服务器错误。

Swagger 还展示了:

GET  api/account/{fiscalYear}
但不显示参数。试了一下也没有显示任何参数。 这在 Spring Boot 2.7.15 上运行良好,但在迁移到 Spring Boot 2.7.15 后出现问题

@RequestMapping("api/account")
public class AccountController {

    @Autowired
    AccountService accountService;


    @GetMapping(path = "/{fiscalYear}")
    public Response getAccountDetails(@PathVariable int fiscalYear) {
    ....
    }
}

更新了所有 pom 条目以反映 Spring Boot 3.2.1

java spring spring-boot rest
1个回答
0
投票

这不是答案,只是写在这里来显示代码。这段代码对我有用

@RestController
@RequestMapping("api/account")
public class LoginController {

    @GetMapping("/{fiscalYear}")
    String register(@PathVariable int fiscalYear) {
        return "Hello world "+fiscalYear+"!";
    }

}

可能错误出现在方法内部的某个地方。在进一步操作之前尝试记录财政年度。 HTTP 500 之后的服务器日志中有什么?

© www.soinside.com 2019 - 2024. All rights reserved.