Spring Boot Whitelabel Error page (type=Not Found, status=404)

前端 未结 5 2245
离开以前
离开以前 2021-02-19 10:31

Good afternoon! I\'m starting spring studies, I\'m following a tutorial the same way, but it returns an error:

Folder structure:

The strange th

5条回答
  •  再見小時候
    2021-02-19 11:02

    Solution: If you are using @Controller over the Controller class then it will be treated as a MVC controller class. But if you want a special controller used in RESTFul web services then you to use @Controller along with @ResponseBody annotation or you can directly use @RestController over the Controller class. It worked for me as I was getting the same error while creating SpringBoot project with RestFul webservices.

    package br.com.SpringApp.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @Controller
    public class EventoController {
    
        @RequestMapping("/cadastroEvento")
        @ResponseBody
        public String form() {      
            return "evento/formEvento"; 
        }
    
    }
    

    or:

    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    @RestController
    public class EventoController {
    
        @RequestMapping("/cadastroEvento")
        public String form() {      
            return "evento/formEvento"; 
        }
    
    }
    

提交回复
热议问题