【蠢事】Spring Boot项目启动访问页面报错Initializing Spring DispatcherServlet 'dispatcherServlet'

控制器代码以下所示:web

import org.springframework.web.bind.annotation.GetMapping; public class HelloController { @GetMapping(value="/hello") public Object hello() { return "Hello Mango!"; } }

启动器代码以下所示:spring

@SpringBootApplication public class MangoAdminApplication { public static void main(String[] args) { SpringApplication.run(MangoAdminApplication.class, args); } }

项目可正常启动不报错,可是访问hello页面时,报错内容以下所示app

 

出错缘由:spa

控制器类没有添加RestController注解code

解决方法:blog

在控制器类中添加注解io

import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @GetMapping(value="/hello") public Object hello() { return "Hello Mango!"; } }

成功运行class

相关文章
相关标签/搜索