控制器代码如下所示:

import org.springframework.web.bind.annotation.GetMapping;

public class HelloController {
    @GetMapping(value="/hello")
    public Object hello() {
        return "Hello Mango!";
    }
}

启动器代码如下所示:

@SpringBootApplication
public class MangoAdminApplication {

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

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

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

 

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

出错原因:

控制器类没有添加RestController注解

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

解决方法:

在控制器类中添加注解

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!";
    }
}

成功运行

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

 

相关文章:

  • 2022-01-13
  • 2021-04-09
  • 2021-07-25
  • 2021-06-23
  • 2022-01-15
猜你喜欢
  • 2021-12-04
  • 2022-12-23
  • 2022-02-27
  • 2022-02-05
  • 2022-02-12
  • 2022-01-03
  • 2022-02-07
相关资源
相似解决方案