【发布时间】:2025-11-30 23:40:01
【问题描述】:
我正在使用 Spring Rest API 创建应用程序。我面临一个奇怪的问题,一次只有 1 个线程能够访问 Controller 方法。 下面是代码sn-p。
如果调用了多个rest服务即getSample,此时只有1个线程在执行该方法,其余线程正在等待完成。与同步方法的工作相同
提前致谢。
@RestController
Class Sample {
@RequestMapping(value = "/controller/sample", method = RequestMethod.POST)
@ResponseBody
public Object getSample(@RequestBody String input) {
System.out.println("Hello World !!")
}
}
【问题讨论】:
-
您能否分享一下,您如何得出结论认为它像同步方法一样工作?
-
可能调用者是同步的?您是否尝试过使用多个浏览器选项卡和 GET 映射?
-
这很奇怪。请分享修改后的 spring 文件(如果有)和/或 application.properties、pom.xml
标签: java spring spring-boot spring-restcontroller