Spring 启动休息:通过 Postman 发送简单的获取请求时找不到错误 404?

Spring Boot Rest : Error 404 not found when sending simple get request via Postman?

我是新邮递员,刚刚安装。我有 spring 使用 maven 启动简单的应用程序构建 和 运行 通过 STS 嵌入 tomcat。 我正在尝试发送获取请求:

http://localhost/9009/locations/Cntry

这是来自控制器的代码:

@RestController
@RequestMapping("locations")
@Slf4j
public class LocationController {

    @Autowired
    LocationService  locationService;
    
    @GetMapping("Cntry")    
    public List<Country> getCountries() {
        return locationService.getdCountries();
    }

我在点击发送时收到邮递员的 404 错误:

{
    "timestamp": "2021-07-09T03:40:36.764+00:00",
    "status": 404,
    "error": "Not Found",
    "path": "/9009/locations/Cntry"
}

我之前有 401 错误,我通过注释 spring pom 文件的安全性修复了它(我没有 实施安全)。理想情况下,spring 安全性应该取消注释。

谢谢。

你的邮递员URL错了。并在控制器级别更正 URL。

@GetMapping("/Cntry")

@RequestMapping("/locations")

9009 端口号应该如下所示。

并确认您的 PORT 号码是否正确,默认情况下它将 运行 在 8080 如果您想要自定义 运行ning 端口 运行 然后在应用程序属性文件中添加以下配置。

server.port=9009

http://localhost:9009/locations/Cntry