首页 > 解决方案 > Spring Boot Rest:通过邮递员发送简单的获取请求时找不到错误 404?

问题描述

我是新邮递员,刚刚安装。我有使用 maven 构建的 spring boot 简单应用程序,并通过 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 错误,我通过 pom 文件中的评论 spring security 修复了它(我还没有实现安全性)。理想情况下,弹簧安全应该取消注释。

谢谢。

标签: springspring-bootpostman

解决方案


您的邮递员网址错误。并在控制器级别更正 URL。

@GetMapping("/Cntry")

@RequestMapping("/locations")

9009 端口号应该如下所示。

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

server.port=9009

http://localhost:9009/locations/Cntry

推荐阅读