Spring boot 2.1.0 release 获取 404 not found 错误

我一直在尝试在 2.1.0 版本中运行 spring boot。即使在尝试访问 localhost:8080 时,我也收到 404 错误。我已经修改了同一个主包中的所有控制器和服务,但没有运气。任何帮助表示赞赏。下面是我的控制台日志.. 甚至 localhost:8080 也不工作。

控制器类:


    @RestController

    public class MobilityApi {



        @Autowired

        private MobilityService mobilityService;


        @RequestMapping(method=RequestMethod.GET,value="/mobilityCC")

        public Response retrieveOrderDetails(@QueryParam("orderid") String orderid) {

            return mobilityService.getOrderDetails(orderid);

        }


一只萌萌小番薯
浏览 255回答 1
1回答

回首忆惘然

似乎Spring没有读取您的Controller,这似乎是一个结构问题。请考虑进行以下更改:@RestController@RequestMapping("/your_decide/")public class MobilityApi {&nbsp; &nbsp; @Autowired&nbsp; &nbsp; private MobilityService mobilityService;&nbsp; &nbsp; @GetMapping("/mobilityCC")&nbsp; &nbsp; public Response retrieveOrderDetails(@RequestParam("orderid") String orderid) {&nbsp; &nbsp; &nbsp; &nbsp; return mobilityService.getOrderDetails(orderid);&nbsp; &nbsp; }}而且,您的主类必须位于根文件夹中。像这样的东西:要消耗其余端点,请尝试访问 localhost:8080/your_decide/mobilityCC编辑:确保您具有 spring-web 依赖项。&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>org.springframework.boot</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>spring-boot-starter-web</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>${spring-boot.version}</version>&nbsp; &nbsp; </dependency>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java