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